Skip to content

Commit e9f4d80

Browse files
authored
gh-120417: Add #noqa: F401 to tests (#120627)
Ignore linter "imported but unused" warnings in tests when the linter doesn't understand how the import is used.
1 parent 7e189ae commit e9f4d80

24 files changed

+43
-41
lines changed

Lib/test/support/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ def refcount_test(test):
12211221

12221222
def requires_limited_api(test):
12231223
try:
1224-
import _testcapi
1225-
import _testlimitedcapi
1224+
import _testcapi # noqa: F401
1225+
import _testlimitedcapi # noqa: F401
12261226
except ImportError:
12271227
return unittest.skip('needs _testcapi and _testlimitedcapi modules')(test)
12281228
return test
@@ -2299,7 +2299,7 @@ def clear_ignored_deprecations(*tokens: object) -> None:
22992299
def requires_venv_with_pip():
23002300
# ensurepip requires zlib to open ZIP archives (.whl binary wheel packages)
23012301
try:
2302-
import zlib
2302+
import zlib # noqa: F401
23032303
except ImportError:
23042304
return unittest.skipIf(True, "venv: ensurepip requires zlib")
23052305

Lib/test/test___all__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_all(self):
103103
# In case _socket fails to build, make this test fail more gracefully
104104
# than an AttributeError somewhere deep in concurrent.futures, email
105105
# or unittest.
106-
import _socket
106+
import _socket # noqa: F401
107107

108108
ignored = []
109109
failed_imports = []

Lib/test/test_asyncio/test_tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,14 +3103,14 @@ def test_asyncio_module_compiled(self):
31033103
# fail on systems where C modules were successfully compiled
31043104
# (hence the test for _functools etc), but _asyncio somehow didn't.
31053105
try:
3106-
import _functools
3107-
import _json
3108-
import _pickle
3106+
import _functools # noqa: F401
3107+
import _json # noqa: F401
3108+
import _pickle # noqa: F401
31093109
except ImportError:
31103110
self.skipTest('C modules are not available')
31113111
else:
31123112
try:
3113-
import _asyncio
3113+
import _asyncio # noqa: F401
31143114
except ImportError:
31153115
self.fail('_asyncio module is missing')
31163116

Lib/test/test_capi/check_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def import_singlephase():
1111
assert '_testsinglephase' not in sys.modules
1212
try:
13-
import _testsinglephase
13+
import _testsinglephase # noqa: F401
1414
except ImportError:
1515
sys.modules.pop('_testsinglephase', None)
1616
return False

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ def test_xdev(self):
737737

738738
# Memory allocator debug hooks
739739
try:
740-
import _testinternalcapi
740+
import _testinternalcapi # noqa: F401
741741
except ImportError:
742742
pass
743743
else:
@@ -754,7 +754,7 @@ def test_xdev(self):
754754

755755
# Faulthandler
756756
try:
757-
import faulthandler
757+
import faulthandler # noqa: F401
758758
except ImportError:
759759
pass
760760
else:

Lib/test/test_codecs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ def test_seek0(self):
29582958
bytes_transform_encodings.append("zlib_codec")
29592959
transform_aliases["zlib_codec"] = ["zip", "zlib"]
29602960
try:
2961-
import bz2
2961+
import bz2 # noqa: F401
29622962
except ImportError:
29632963
pass
29642964
else:

Lib/test/test_compile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ class A:
441441
def f():
442442
__mangled = 1
443443
__not_mangled__ = 2
444-
import __mangled_mod
445-
import __package__.module
444+
import __mangled_mod # noqa: F401
445+
import __package__.module # noqa: F401
446446

447447
self.assertIn("_A__mangled", A.f.__code__.co_varnames)
448448
self.assertIn("__not_mangled__", A.f.__code__.co_varnames)

Lib/test/test_compileall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# compileall relies on ProcessPoolExecutor if ProcessPoolExecutor exists
1919
# and it can function.
2020
from multiprocessing.util import _cleanup_tests as multiprocessing_cleanup_tests
21-
from concurrent.futures import ProcessPoolExecutor
21+
from concurrent.futures import ProcessPoolExecutor # noqa: F401
2222
from concurrent.futures.process import _check_system_limits
2323
_check_system_limits()
2424
_have_multiprocessing = True

Lib/test/test_descrtut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# of much interest anymore), and a few were fiddled to make the output
99
# deterministic.
1010

11-
from test.support import sortdict
11+
from test.support import sortdict # noqa: F401
1212
import doctest
1313
import unittest
1414

Lib/test/test_file_eintr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
raise unittest.SkipTest("test module requires subprocess")
2222

2323
# Test import all of the things we're about to try testing up front.
24-
import _io
25-
import _pyio
24+
import _io # noqa: F401
25+
import _pyio # noqa: F401
2626

2727
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
2828
class TestFileIOSignalInterrupt:

0 commit comments

Comments
 (0)