Skip to content

Commit a88a5bd

Browse files
authored
Merge pull request #1187 from MVrachev/change-aggregate-test
Simplify aggregate_tests.py
2 parents 6cb9d45 + fa899cc commit a88a5bd

File tree

2 files changed

+8
-53
lines changed

2 files changed

+8
-53
lines changed

tests/aggregate_tests.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,61 +36,9 @@
3636

3737
import sys
3838
import unittest
39-
import glob
40-
import random
41-
42-
# Generate a list of pathnames that match a pattern (i.e., that begin with
43-
# 'test_' and end with '.py'. A shell-style wildcard is used with glob() to
44-
# match desired filenames. All the tests matching the pattern will be loaded
45-
# and run in a test suite.
46-
available_tests = glob.glob('test_*.py')
47-
48-
# A dictionary of test modules that should only run in certain python versions.
49-
# Carefully consider the impact of only testing these in a given version.
50-
# test_proxy_use.py: uses a proxy that only runs in Python2.7. TUF's
51-
# compatibility with proxies is not likely to vary based on the Python version
52-
# in use, so this is OK for now. See comments in that module.
53-
# The semantics here are: only add to this list the particular tests that are
54-
# to be run in a single major version or a single minor version. An entry must
55-
# include major version, and may include minor version.
56-
# Skip the test if any such listed constraints don't match the python version
57-
# currently running.
58-
# Note that aggregate_tests.py is run for each version of Python that tox is
59-
# configured to use. Note also that this TUF implementation does not support
60-
# any Python versions <2.7 or any Python3 versions <3.4.
61-
VERSION_SPECIFIC_TESTS = {
62-
'test_proxy_use': {'major': 2, 'minor': 7}} # Run test only if Python2.7
63-
# Further example:
64-
# 'test_abc': {'major': 2} # Run test only if Python2
65-
66-
# Determine which tests should be run.
67-
test_modules_to_run = []
68-
for test in available_tests:
69-
# Remove '.py' from each filename to allow loadTestsFromNames() (called below)
70-
# to properly load the file as a module.
71-
assert test[-3:] == '.py', 'aggregate_tests.py is inconsistent; fix.'
72-
test = test[:-3]
73-
74-
if test in VERSION_SPECIFIC_TESTS:
75-
# Consistency checks.
76-
assert 'major' in VERSION_SPECIFIC_TESTS[test], 'Empty/illogical constraint'
77-
for keyword in VERSION_SPECIFIC_TESTS[test]:
78-
assert keyword in ['major', 'minor'], 'Unrecognized test constraint'
79-
80-
if sys.version_info.major != VERSION_SPECIFIC_TESTS[test]['major']:
81-
continue
82-
if 'minor' in VERSION_SPECIFIC_TESTS[test] \
83-
and sys.version_info.minor != VERSION_SPECIFIC_TESTS[test]['minor']:
84-
continue
85-
test_modules_to_run.append(test)
86-
87-
# Randomize the order in which the tests run. Randomization might catch errors
88-
# with unit tests that do not properly clean up or restore monkey-patched
89-
# modules.
90-
random.shuffle(test_modules_to_run)
9139

9240
if __name__ == '__main__':
93-
suite = unittest.TestLoader().loadTestsFromNames(test_modules_to_run)
41+
suite = unittest.TestLoader().discover(".")
9442
all_tests_passed = unittest.TextTestRunner(
9543
verbosity=1, buffer=True).run(suite).wasSuccessful()
9644

tests/test_proxy_use.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@
5252

5353
logger = logging.getLogger(__name__)
5454

55+
IS_PY_VERSION_SUPPORTED = sys.version_info == (2, 7)
56+
57+
# Use setUpModule to tell unittest runner to skip this test module gracefully.
58+
def setUpModule():
59+
if not IS_PY_VERSION_SUPPORTED:
60+
raise unittest.SkipTest('requires Python 2.7')
61+
5562
class TestWithProxies(unittest_toolbox.Modified_TestCase):
5663

5764
@classmethod

0 commit comments

Comments
 (0)