Skip to content

Commit 042bf76

Browse files
vstinnerestyxx
authored andcommitted
pythongh-120417: Use import_helper() in test_regrtest (python#120680)
1 parent dc1129a commit 042bf76

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Lib/test/test_regrtest.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import textwrap
2323
import unittest
2424
from test import support
25-
from test.support import os_helper, without_optimizer
25+
from test.support import import_helper
26+
from test.support import os_helper
2627
from test.libregrtest import cmdline
2728
from test.libregrtest import main
2829
from test.libregrtest import setup
@@ -1178,7 +1179,7 @@ def test_run(self):
11781179
stats=TestStats(4, 1),
11791180
forever=True)
11801181

1181-
@without_optimizer
1182+
@support.without_optimizer
11821183
def check_leak(self, code, what, *, run_workers=False):
11831184
test = self.create_test('huntrleaks', code=code)
11841185

@@ -1746,10 +1747,9 @@ def test_other_bug(self):
17461747

17471748
@support.cpython_only
17481749
def test_uncollectable(self):
1749-
try:
1750-
import _testcapi
1751-
except ImportError:
1752-
raise unittest.SkipTest("requires _testcapi")
1750+
# Skip test if _testcapi is missing
1751+
import_helper.import_module('_testcapi')
1752+
17531753
code = textwrap.dedent(r"""
17541754
import _testcapi
17551755
import gc
@@ -2132,10 +2132,10 @@ def test_unload_tests(self):
21322132

21332133
def check_add_python_opts(self, option):
21342134
# --fast-ci and --slow-ci add "-u -W default -bb -E" options to Python
2135-
try:
2136-
import _testinternalcapi
2137-
except ImportError:
2138-
raise unittest.SkipTest("requires _testinternalcapi")
2135+
2136+
# Skip test if _testinternalcapi is missing
2137+
import_helper.import_module('_testinternalcapi')
2138+
21392139
code = textwrap.dedent(r"""
21402140
import sys
21412141
import unittest
@@ -2198,10 +2198,8 @@ def test_add_python_opts(self):
21982198
@unittest.skipIf(support.is_android,
21992199
'raising SIGSEGV on Android is unreliable')
22002200
def test_worker_output_on_failure(self):
2201-
try:
2202-
from faulthandler import _sigsegv
2203-
except ImportError:
2204-
self.skipTest("need faulthandler._sigsegv")
2201+
# Skip test if faulthandler is missing
2202+
import_helper.import_module('faulthandler')
22052203

22062204
code = textwrap.dedent(r"""
22072205
import faulthandler

0 commit comments

Comments
 (0)