From 074e53a20bce0ee3c70c90743d0ece63558cf441 Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Sun, 4 Aug 2019 10:24:26 +0700 Subject: [PATCH] .ci/get_tests.py: Add dynamic test skip list Custom rules in tox.ini are migrated into get_tests.py so that they can be documented and dynamically collated together. Related to https://github.com/coala/coala-bears/issues/1476 --- .ci/get_tests.py | 40 ++++++++++++++++++++++++++++++++++++++-- tox.ini | 5 ++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.ci/get_tests.py b/.ci/get_tests.py index 3ea95d1f21..23e705ab21 100755 --- a/.ci/get_tests.py +++ b/.ci/get_tests.py @@ -21,7 +21,6 @@ WINDOWS_BROKEN = set(( 'bakalint', # not installed 'phpcs', # https://github.com/coala/coala-bears/issues/2916 - 'pmd', 'cpd', # https://github.com/coala/coala-bears/issues/2908 'mcs', # choco mono isnt providing this in the PATH 'tailor', # installer fails 'shellcheck', # https://github.com/coala/coala-bears/issues/2920 @@ -123,14 +122,34 @@ def get_tests(bears): return tests +def get_pytest_deselected_tests(args, tests): + not_list = [] + + # language-check fails for different locale on windows + if 'tests/documentation/DocGrammarBearTest.py' in tests: + if 'win' in args: + not_list.append('test_language_french') + + # async is not available on Python 3.4 + if 'tests/python/YapfBearTest.py' in tests: + if 'py34' in args: + not_list.append('test_valid_async') + + return not_list + + def main(): args_orig = sys.argv[1:] metadata = get_metadata() include_disabled = False + show_deselected = False if args_orig[0] == '--disabled': include_disabled = True args_orig = args_orig[1:] + elif args_orig[0] == '--deselected': + show_deselected = True + args_orig = args_orig[1:] args = [] for arg in args_orig: @@ -149,7 +168,24 @@ def main(): bears = get_bears(metadata, args, include_disabled) tests = get_tests(bears) - print(' '.join(sorted(tests))) + if show_deselected: + not_list = get_pytest_deselected_tests(args, tests) + deselect_list = [item for item in not_list if '::' in item] + not_list = [item for item in not_list if item not in deselect_list] + if len(not_list) > 1: + not_list = '-k "not ({})"'.format(' or '.join(not_list)) + elif len(not_list) == 1: + not_list = '-k "not {}"'.format(not_list[0]) + else: + not_list = '' + if deselect_list: + deselect_list = ' --deselect={}'.format( + ' --deselect='.join(deselect_list)) + else: + deselect_list = '' + print(not_list + deselect_list) + else: + print(' '.join(sorted(tests))) if __name__ == '__main__': diff --git a/tox.ini b/tox.ini index 3b72e9ed6d..a94d8b655e 100644 --- a/tox.ini +++ b/tox.ini @@ -100,15 +100,14 @@ setenv = adhoc: ADHOCBEARS=`python .ci/get_tests.py {env:BEAR_LIST}` disabled: DISABLEDBEARS=`python .ci/get_tests.py --disabled {env:BEAR_LIST}` SELECTED={env:ENVNAMEBEARS:} {env:ADHOCBEARS:} {env:DISABLEDBEARS:} + PYTEST_DESELECT_ARGS=`python .ci/get_tests.py --deselected {envname} {env:BEAR_LIST:}` noskip: PYTEST_ARGS=--error-for-skips - py34-noskip: PYTEST_ARGS=--error-for-skips -k 'not test_valid_async' - win-noskip: PYTEST_ARGS=--error-for-skips -k 'not test_language_french and not test_valid_async' collectonly,list: PYTEST_ARGS=--collect-only codecov: CODECOV_FLAGS=`python .ci/get_codecov_tags.py {envname}` commands = check,list,all: python .ci/get_bears.py --missing {env:SELECTED} !py34,!apt_get: python .ci/generate_coverage_thresholds.py {posargs:{env:SELECTED}} py34,apt_get: python .ci/generate_coverage_thresholds.py none - !list: pytest {env:PYTEST_ARGS:} --cov --cov-fail-under=0 --continue-on-collection-errors --cov-report term-missing:skip-covered --deselect=requirements.txt {posargs:{env:SELECTED}} + !list: pytest {env:PYTEST_ARGS:} --cov --cov-fail-under=0 --continue-on-collection-errors --cov-report term-missing:skip-covered --deselect=requirements.txt {posargs:{env:SELECTED}} {env:PYTEST_DESELECT_ARGS:} commands_post = codecov: codecov --name={envname} --flags={env:CODECOV_FLAGS}