|
36 | 36 |
|
37 | 37 | import sys |
38 | 38 | 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) |
91 | 39 |
|
92 | 40 | if __name__ == '__main__': |
93 | | - suite = unittest.TestLoader().loadTestsFromNames(test_modules_to_run) |
| 41 | + suite = unittest.TestLoader().discover(".") |
94 | 42 | all_tests_passed = unittest.TextTestRunner( |
95 | 43 | verbosity=1, buffer=True).run(suite).wasSuccessful() |
96 | 44 |
|
|
0 commit comments