diff options
author | Max Romanov <max.romanov@nginx.com> | 2020-09-24 09:47:27 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2020-09-24 09:47:27 +0300 |
commit | efe65dee4de9d429a3cd0d7e88e4999a8c89081a (patch) | |
tree | af88914f1d2f460ab7d27963dc0d9d2922242d20 /test | |
parent | 1fc51cf140d22958d6dcf7e7729826b0f9671fd7 (diff) | |
download | unit-efe65dee4de9d429a3cd0d7e88e4999a8c89081a.tar.gz unit-efe65dee4de9d429a3cd0d7e88e4999a8c89081a.tar.bz2 |
Tests: prerequisites check improved by using callable.
This is required for more flexible Python version check since ASGI works
for Python 3.5+. Version check via 'startswith()' function removed as
not consistent.
Diffstat (limited to 'test')
-rw-r--r-- | test/conftest.py | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/test/conftest.py b/test/conftest.py index 8683a023..6bc871e2 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -67,32 +67,40 @@ def pytest_generate_tests(metafunc): type = cls.application_type + def generate_tests(versions): + metafunc.fixturenames.append('tmp_ct') + metafunc.parametrize('tmp_ct', range(len(versions))) + + for i, version in enumerate(versions): + option.generated_tests[ + metafunc.function.__name__ + '[{}]'.format(i) + ] = (type + ' ' + version) + # take available module from option and generate tests for each version - for module in cls.prerequisites['modules']: + for module, prereq_version in cls.prerequisites['modules'].items(): if module in option.available['modules']: - prereq_version = cls.prerequisites['modules'][module] available_versions = option.available['modules'][module] if prereq_version == 'all': - metafunc.fixturenames.append('tmp_ct') - metafunc.parametrize('tmp_ct', range(len(available_versions))) - - for i in range(len(available_versions)): - version = available_versions[i] - option.generated_tests[ - metafunc.function.__name__ + '[{}]'.format(i) - ] = (type + ' ' + version) + generate_tests(available_versions) + elif prereq_version == 'any': option.generated_tests[metafunc.function.__name__] = ( type + ' ' + available_versions[0] ) + elif callable(prereq_version): + generate_tests( + list(filter(prereq_version, available_versions)) + ) + else: - for version in available_versions: - if version.startswith(prereq_version): - option.generated_tests[metafunc.function.__name__] = ( - type + ' ' + version - ) + raise ValueError( + """ +Unexpected prerequisite version "%s" for module "%s" in %s. +'all', 'any' or callable expected.""" + % (str(prereq_version), module, str(cls)) + ) def pytest_sessionstart(session): |