summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-27 14:35:18 (GMT)
committerGitHub <noreply@github.com>2017-06-27 14:35:18 (GMT)
commitde1850bb03f8225cbff85f437b6e972bf9b68c2a (patch)
treea94999f74e1593ea276c26eaeaae49f8181318ee /Lib/test/regrtest.py
parenteef254d6c6b13db2f3d6a2f219bc76e84416f59c (diff)
downloadcpython-de1850bb03f8225cbff85f437b6e972bf9b68c2a.zip
cpython-de1850bb03f8225cbff85f437b6e972bf9b68c2a.tar.gz
cpython-de1850bb03f8225cbff85f437b6e972bf9b68c2a.tar.bz2
[3.5] bpo-30523, bpo-30764, bpo-30776: Sync regrtest from master (#2442)
* bpo-30523: regrtest --list-cases --match (#2401) * regrtest --list-cases now supports --match and --match-file options. Example: ./python -m test --list-cases -m FileTests test_os * --list-cases now also sets support.verbose to False to prevent messages to stdout when loading test modules. * Add support._match_test() private function. (cherry picked from commit ace56d583664f855d89d1219ece7c21c2fddcf30) * bpo-30764: regrtest: add --fail-env-changed option (#2402) * bpo-30764: regrtest: change exit code on failure * Exit code 2 if failed tests ("bad") * Exit code 3 if interrupted * bpo-30764: regrtest: add --fail-env-changed option If the option is set, mark a test as failed if it alters the environment, for example if it creates a file without removing it. (cherry picked from commit 63f54c68936d648c70ca411661e4208329edcf26) * bpo-30776: reduce regrtest -R false positives (#2422) * Change the regrtest --huntrleaks checker to decide if a test file leaks or not. Require that each run leaks at least 1 reference. * Warmup runs are now completely ignored: ignored in the checker test and not used anymore to compute the sum. * Add an unit test for a reference leak. Example of reference differences previously considered a failure (leak) and now considered as success (success, no leak): [3, 0, 0] [0, 1, 0] [8, -8, 1] (cherry picked from commit 48b5c422ffb03affb00c184b9a99e5537be92732)
Diffstat (limited to 'Lib/test/regrtest.py')
-rwxr-xr-xLib/test/regrtest.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 299416c..339beb1 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -343,6 +343,9 @@ def _create_parser():
' , don\'t execute them')
group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
help='enable Profile Guided Optimization training')
+ group.add_argument('--fail-env-changed', action='store_true',
+ help='if a test file alters the environment, mark '
+ 'the test as failed')
return parser
@@ -944,11 +947,19 @@ def main(tests=None, **kwargs):
result = "FAILURE"
elif interrupted:
result = "INTERRUPTED"
+ elif environment_changed and ns.fail_env_changed:
+ result = "ENV CHANGED"
else:
result = "SUCCESS"
print("Tests result: %s" % result)
- sys.exit(len(bad) > 0 or interrupted)
+ if bad:
+ sys.exit(2)
+ if interrupted:
+ sys.exit(130)
+ if ns.fail_env_changed and environment_changed:
+ sys.exit(3)
+ sys.exit(0)
# small set of tests to determine if we have a basically functioning interpreter
@@ -1510,9 +1521,21 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
alloc_deltas[i] = alloc_after - alloc_before
alloc_before, rc_before = alloc_after, rc_after
print(file=sys.stderr)
+
# These checkers return False on success, True on failure
def check_rc_deltas(deltas):
- return any(deltas)
+ # bpo-30776: Try to ignore false positives:
+ #
+ # [3, 0, 0]
+ # [0, 1, 0]
+ # [8, -8, 1]
+ #
+ # Expected leaks:
+ #
+ # [5, 5, 6]
+ # [10, 1, 1]
+ return all(delta >= 1 for delta in deltas)
+
def check_alloc_deltas(deltas):
# At least 1/3rd of 0s
if 3 * deltas.count(0) < len(deltas):
@@ -1524,10 +1547,13 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
failed = False
for deltas, item_name, checker in [
(rc_deltas, 'references', check_rc_deltas),
- (alloc_deltas, 'memory blocks', check_alloc_deltas)]:
+ (alloc_deltas, 'memory blocks', check_alloc_deltas)
+ ]:
+ # ignore warmup runs
+ deltas = deltas[nwarmup:]
if checker(deltas):
msg = '%s leaked %s %s, sum=%s' % (
- test, deltas[nwarmup:], item_name, sum(deltas))
+ test, deltas, item_name, sum(deltas))
print(msg, file=sys.stderr)
sys.stderr.flush()
with open(fname, "a") as refrep:
@@ -1735,10 +1761,14 @@ def _list_cases(suite):
if isinstance(test, unittest.TestSuite):
_list_cases(test)
elif isinstance(test, unittest.TestCase):
- print(test.id())
+ if support._match_test(test):
+ print(test.id())
def list_cases(ns, selected):
+ support.verbose = False
+ support.match_tests = ns.match_tests
+
skipped = []
for test in selected:
abstest = get_abs_module(ns, test)