Skip to content

Commit 4b459a3

Browse files
Exclude tests if there are no credentials in VCAP_SERVICES
1 parent 09bc8a8 commit 4b459a3

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

test/test_examples.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import os
44

55
import pytest
6+
import json as json_import
7+
68
from os.path import join, dirname
79
from glob import glob
810

911
# tests to exclude
10-
excludes = ['authorization_v1.py', 'alchemy_data_news_v1.py', 'alchemy_language_v1.py']
12+
excludes = ['authorization_v1.py', 'alchemy_data_news_v1.py', 'alchemy_language_v1.py', 'discovery_v1.ipynb', '__init__.py']
1113

1214
# examples path. /examples
1315
examples_path = join(dirname(__file__), '../', 'examples', '*.py')
@@ -27,15 +29,23 @@
2729

2830
@pytest.mark.skipif(os.getenv('VCAP_SERVICES') is None, reason='requires VCAP_SERVICES')
2931
def test_examples():
32+
vcapServices = json_import.loads(os.getenv('VCAP_SERVICES'))
3033
examples = glob(examples_path)
3134
for example in examples:
3235
name = example.split('/')[-1]
36+
3337
# exclude some tests cases like authorization
3438
if name in excludes:
3539
continue
3640

41+
# exclude tests if there are no credentials for that service
42+
serviceName = name[:-6] if not name.startswith('visual_recognition') else 'watson_vision_combined'
43+
44+
if serviceName not in vcapServices:
45+
print('%s does not have credentials in VCAP_SERVICES', serviceName)
46+
continue
47+
3748
try:
3849
exec(open(example).read(), globals())
3950
except Exception as e:
4051
assert False, 'example in file ' + name + ' failed with error: ' + str(e)
41-

0 commit comments

Comments
 (0)