Skip to content

Commit 2da0dc0

Browse files
authored
gh-119659: Move @no_rerun to test.support (#119660)
1 parent f912e5a commit 2da0dc0

File tree

3 files changed

+21
-41
lines changed

3 files changed

+21
-41
lines changed

Lib/test/datetimetester.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from test import support
2424
from test.support import is_resource_enabled, ALWAYS_EQ, LARGEST, SMALLEST
25-
from test.support import warnings_helper
25+
from test.support import warnings_helper, no_rerun
2626

2727
import datetime as datetime_module
2828
from datetime import MINYEAR, MAXYEAR
@@ -47,26 +47,6 @@
4747
pass
4848
#
4949

50-
# This is copied from test_import/__init__.py.
51-
# XXX Move it to support/__init__.py.
52-
def no_rerun(reason):
53-
"""Skip rerunning for a particular test.
54-
55-
WARNING: Use this decorator with care; skipping rerunning makes it
56-
impossible to find reference leaks. Provide a clear reason for skipping the
57-
test using the 'reason' parameter.
58-
"""
59-
def deco(func):
60-
_has_run = False
61-
def wrapper(self):
62-
nonlocal _has_run
63-
if _has_run:
64-
self.skipTest(reason)
65-
func(self)
66-
_has_run = True
67-
return wrapper
68-
return deco
69-
7050
pickle_loads = {pickle.loads, pickle._loads}
7151

7252
pickle_choices = [(pickle, pickle, proto)

Lib/test/support/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,25 @@ def coverage_wrapper(*args, **kwargs):
11891189
return coverage_wrapper
11901190

11911191

1192+
def no_rerun(reason):
1193+
"""Skip rerunning for a particular test.
1194+
1195+
WARNING: Use this decorator with care; skipping rerunning makes it
1196+
impossible to find reference leaks. Provide a clear reason for skipping the
1197+
test using the 'reason' parameter.
1198+
"""
1199+
def deco(func):
1200+
_has_run = False
1201+
def wrapper(self):
1202+
nonlocal _has_run
1203+
if _has_run:
1204+
self.skipTest(reason)
1205+
func(self)
1206+
_has_run = True
1207+
return wrapper
1208+
return deco
1209+
1210+
11921211
def refcount_test(test):
11931212
"""Decorator for tests which involve reference counting.
11941213

Lib/test/test_import/__init__.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from test.support import (
3232
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_apple_mobile, is_emscripten,
3333
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS,
34-
requires_gil_enabled, Py_GIL_DISABLED)
34+
requires_gil_enabled, Py_GIL_DISABLED, no_rerun)
3535
from test.support.import_helper import (
3636
forget, make_legacy_pyc, unlink, unload, ready_to_import,
3737
DirsOnSysPath, CleanImport, import_module)
@@ -120,25 +120,6 @@ def remove_files(name):
120120
rmtree('__pycache__')
121121

122122

123-
def no_rerun(reason):
124-
"""Skip rerunning for a particular test.
125-
126-
WARNING: Use this decorator with care; skipping rerunning makes it
127-
impossible to find reference leaks. Provide a clear reason for skipping the
128-
test using the 'reason' parameter.
129-
"""
130-
def deco(func):
131-
_has_run = False
132-
def wrapper(self):
133-
nonlocal _has_run
134-
if _has_run:
135-
self.skipTest(reason)
136-
func(self)
137-
_has_run = True
138-
return wrapper
139-
return deco
140-
141-
142123
if _testsinglephase is not None:
143124
def restore__testsinglephase(*, _orig=_testsinglephase):
144125
# We started with the module imported and want to restore

0 commit comments

Comments
 (0)