Skip to content

Commit 01d8d9e

Browse files
committed
Test: tighten test-skip conditions and lengthen a subprocess sleep
After seeing some AppVeyor failures, I've increased the wait after starting test HTTP, HTTPS, and proxy servers from 0.5s to 1s, to make it less likely that tests will fail because the servers weren't done starting up yet. After some review comments by @aaaaalbert, I've tightened the logic in aggregate_tests.py around which tests to skip unless a certain Python version is running, and added some consistency checks. This also involved a bit of clarification of comments and variable names. Signed-off-by: Sebastien Awwad <sebastien.awwad@gmail.com>
1 parent ebcb17b commit 01d8d9e

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

tests/aggregate_tests.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,54 @@
4343
# 'test_' and end with '.py'. A shell-style wildcard is used with glob() to
4444
# match desired filenames. All the tests matching the pattern will be loaded
4545
# and run in a test suite.
46-
tests_list = glob.glob('test_*.py')
46+
available_tests = glob.glob('test_*.py')
4747

4848
# A dictionary of test modules that should only run in certain python versions.
4949
# Carefully consider the impact of only testing these in a given version.
5050
# test_proxy_use.py: uses a proxy that only runs in Python2.7. TUF's
5151
# compatibility with proxies is not likely to vary based on the Python version
5252
# in use, so this is OK for now. See comments in that module.
53-
# The format here is: if major is included, limit version to that listed here.
54-
# If minor is included, limit version to that listed here. Skip the test if any
55-
# such listed constraints don't match the python version currently running.
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.
5661
VERSION_SPECIFIC_TESTS = {
5762
'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
5865

59-
# Remove '.py' from each filename to allow loadTestsFromNames() (called below)
60-
# to properly load the file as a module.
61-
tests_without_extension = []
62-
for test in tests_list:
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.'
6372
test = test[:-3]
73+
6474
if test in VERSION_SPECIFIC_TESTS:
65-
if 'major' in VERSION_SPECIFIC_TESTS[test] \
66-
and sys.version_info.major != VERSION_SPECIFIC_TESTS[test]['major']:
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']:
6781
continue
68-
elif 'minor' in VERSION_SPECIFIC_TESTS[test] \
82+
if 'minor' in VERSION_SPECIFIC_TESTS[test] \
6983
and sys.version_info.minor != VERSION_SPECIFIC_TESTS[test]['minor']:
7084
continue
71-
tests_without_extension.append(test)
85+
test_modules_to_run.append(test)
7286

7387
# Randomize the order in which the tests run. Randomization might catch errors
7488
# with unit tests that do not properly clean up or restore monkey-patched
7589
# modules.
76-
random.shuffle(tests_without_extension)
90+
random.shuffle(test_modules_to_run)
7791

7892
if __name__ == '__main__':
79-
suite = unittest.TestLoader().loadTestsFromNames(tests_without_extension)
93+
suite = unittest.TestLoader().loadTestsFromNames(test_modules_to_run)
8094
all_tests_passed = unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful()
8195
if not all_tests_passed:
8296
sys.exit(1)

tests/test_proxy_use.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def setUpClass(cls):
123123
# start listening before allowing tests to begin, lest we get "Connection
124124
# refused" errors. On the first test system. 0.1s was too short and 0.15s
125125
# was long enough. Use 0.5s to be safe, and if issues arise, increase it.
126-
time.sleep(0.5)
126+
# Observed some occasional AppVeyor failures, so increasing this to 1s.
127+
time.sleep(1)
127128

128129

129130

0 commit comments

Comments
 (0)