Skip to content

Commit adc1974

Browse files
authored
Merge pull request #8555 from The-Compiler/py310-fix
Fix Python 3.10 test issues
2 parents 385988c + 3825992 commit adc1974

12 files changed

+73
-43
lines changed

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ filterwarnings = [
4242
"default:invalid escape sequence:DeprecationWarning",
4343
# ignore use of unregistered marks, because we use many to test the implementation
4444
"ignore::_pytest.warning_types.PytestUnknownMarkWarning",
45+
# https://github.com/benjaminp/six/issues/341
46+
"ignore:_SixMetaPathImporter\\.exec_module\\(\\) not found; falling back to load_module\\(\\):ImportWarning",
47+
# https://github.com/benjaminp/six/pull/352
48+
"ignore:_SixMetaPathImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
49+
# https://github.com/pypa/setuptools/pull/2517
50+
"ignore:VendorImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
51+
# https://github.com/pytest-dev/execnet/pull/127
52+
"ignore:isSet\\(\\) is deprecated, use is_set\\(\\) instead:DeprecationWarning",
4553
]
4654
pytester_example_dir = "testing/example_scripts"
4755
markers = [

testing/acceptance_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ def test_usage_error_code(pytester: Pytester) -> None:
11731173
assert result.ret == ExitCode.USAGE_ERROR
11741174

11751175

1176-
@pytest.mark.filterwarnings("default")
1176+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
11771177
def test_warn_on_async_function(pytester: Pytester) -> None:
11781178
# In the below we .close() the coroutine only to avoid
11791179
# "RuntimeWarning: coroutine 'test_2' was never awaited"
@@ -1206,7 +1206,7 @@ def test_3():
12061206
)
12071207

12081208

1209-
@pytest.mark.filterwarnings("default")
1209+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
12101210
def test_warn_on_async_gen_function(pytester: Pytester) -> None:
12111211
pytester.makepyfile(
12121212
test_async="""

testing/python/collect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ class Test(object):
12371237
assert result.ret == ExitCode.NO_TESTS_COLLECTED
12381238

12391239

1240-
@pytest.mark.filterwarnings("default")
1240+
@pytest.mark.filterwarnings("default::pytest.PytestCollectionWarning")
12411241
def test_dont_collect_non_function_callable(pytester: Pytester) -> None:
12421242
"""Test for issue https://github.com/pytest-dev/pytest/issues/331
12431243

testing/python/metafunc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,10 @@ def test_idmaker_enum(self) -> None:
448448
enum = pytest.importorskip("enum")
449449
e = enum.Enum("Foo", "one, two")
450450
result = idmaker(("a", "b"), [pytest.param(e.one, e.two)])
451-
assert result == ["Foo.one-Foo.two"]
451+
if sys.version_info[:2] >= (3, 10):
452+
assert result == ["one-two"]
453+
else:
454+
assert result == ["Foo.one-Foo.two"]
452455

453456
def test_idmaker_idfn(self) -> None:
454457
"""#351"""

testing/test_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def test_collect_symlink_dir(pytester: Pytester) -> None:
12251225
"""A symlinked directory is collected."""
12261226
dir = pytester.mkdir("dir")
12271227
dir.joinpath("test_it.py").write_text("def test_it(): pass", "utf-8")
1228-
pytester.path.joinpath("symlink_dir").symlink_to(dir)
1228+
symlink_or_skip(pytester.path.joinpath("symlink_dir"), dir)
12291229
result = pytester.runpytest()
12301230
result.assert_outcomes(passed=2)
12311231

testing/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def test_silence_unknown_key_warning(self, pytester: Pytester) -> None:
290290
result = pytester.runpytest()
291291
result.stdout.no_fnmatch_line("*PytestConfigWarning*")
292292

293-
@pytest.mark.filterwarnings("default")
293+
@pytest.mark.filterwarnings("default::pytest.PytestConfigWarning")
294294
def test_disable_warnings_plugin_disables_config_warnings(
295295
self, pytester: Pytester
296296
) -> None:

testing/test_pytester.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,16 @@ def test_run_result_repr() -> None:
744744

745745
# known exit code
746746
r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5)
747-
assert (
748-
repr(r) == "<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
749-
" len(stderr.lines)=4 duration=0.50s>"
750-
)
747+
if sys.version_info[:2] >= (3, 10):
748+
assert repr(r) == (
749+
"<RunResult ret=TESTS_FAILED len(stdout.lines)=3"
750+
" len(stderr.lines)=4 duration=0.50s>"
751+
)
752+
else:
753+
assert repr(r) == (
754+
"<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
755+
" len(stderr.lines)=4 duration=0.50s>"
756+
)
751757

752758
# unknown exit code: just the number
753759
r = pytester_mod.RunResult(99, outlines, errlines, duration=0.5)

testing/test_skipping.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,21 +1143,34 @@ def test_func():
11431143
pypy_version_info = getattr(sys, "pypy_version_info", None)
11441144
if pypy_version_info is not None and pypy_version_info < (6,):
11451145
markline = markline[5:]
1146+
elif sys.version_info[:2] >= (3, 10):
1147+
markline = markline[11:]
11461148
elif sys.version_info >= (3, 8) or hasattr(sys, "pypy_version_info"):
11471149
markline = markline[4:]
1148-
result.stdout.fnmatch_lines(
1149-
[
1150+
1151+
if sys.version_info[:2] >= (3, 10):
1152+
expected = [
11501153
"*ERROR*test_nameerror*",
1151-
"*evaluating*skipif*condition*",
11521154
"*asd*",
1153-
"*ERROR*test_syntax*",
1154-
"*evaluating*xfail*condition*",
1155-
" syntax error",
1156-
markline,
1157-
"SyntaxError: invalid syntax",
1158-
"*1 pass*2 errors*",
1155+
"",
1156+
"During handling of the above exception, another exception occurred:",
11591157
]
1160-
)
1158+
else:
1159+
expected = [
1160+
"*ERROR*test_nameerror*",
1161+
]
1162+
1163+
expected += [
1164+
"*evaluating*skipif*condition*",
1165+
"*asd*",
1166+
"*ERROR*test_syntax*",
1167+
"*evaluating*xfail*condition*",
1168+
" syntax error",
1169+
markline,
1170+
"SyntaxError: invalid syntax",
1171+
"*1 pass*2 errors*",
1172+
]
1173+
result.stdout.fnmatch_lines(expected)
11611174

11621175

11631176
def test_xfail_skipif_with_globals(pytester: Pytester) -> None:

testing/test_terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
16181618
)
16191619

16201620

1621-
@pytest.mark.filterwarnings("default")
1621+
@pytest.mark.filterwarnings("default::UserWarning")
16221622
def test_terminal_summary_warnings_are_displayed(pytester: Pytester) -> None:
16231623
"""Test that warnings emitted during pytest_terminal_summary are displayed.
16241624
(#1305).
@@ -1655,7 +1655,7 @@ def test_failure():
16551655
assert stdout.count("=== warnings summary ") == 2
16561656

16571657

1658-
@pytest.mark.filterwarnings("default")
1658+
@pytest.mark.filterwarnings("default::UserWarning")
16591659
def test_terminal_summary_warnings_header_once(pytester: Pytester) -> None:
16601660
pytester.makepyfile(
16611661
"""

testing/test_threadexception.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytest.skip("threadexception plugin needs Python>=3.8", allow_module_level=True)
99

1010

11-
@pytest.mark.filterwarnings("default")
11+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
1212
def test_unhandled_thread_exception(pytester: Pytester) -> None:
1313
pytester.makepyfile(
1414
test_it="""
@@ -42,7 +42,7 @@ def test_2(): pass
4242
)
4343

4444

45-
@pytest.mark.filterwarnings("default")
45+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
4646
def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None:
4747
pytester.makepyfile(
4848
test_it="""
@@ -78,7 +78,7 @@ def test_2(): pass
7878
)
7979

8080

81-
@pytest.mark.filterwarnings("default")
81+
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
8282
def test_unhandled_thread_exception_in_teardown(pytester: Pytester) -> None:
8383
pytester.makepyfile(
8484
test_it="""

testing/test_unraisableexception.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytest.skip("unraisableexception plugin needs Python>=3.8", allow_module_level=True)
99

1010

11-
@pytest.mark.filterwarnings("default")
11+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
1212
def test_unraisable(pytester: Pytester) -> None:
1313
pytester.makepyfile(
1414
test_it="""
@@ -40,7 +40,7 @@ def test_2(): pass
4040
)
4141

4242

43-
@pytest.mark.filterwarnings("default")
43+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
4444
def test_unraisable_in_setup(pytester: Pytester) -> None:
4545
pytester.makepyfile(
4646
test_it="""
@@ -76,7 +76,7 @@ def test_2(): pass
7676
)
7777

7878

79-
@pytest.mark.filterwarnings("default")
79+
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
8080
def test_unraisable_in_teardown(pytester: Pytester) -> None:
8181
pytester.makepyfile(
8282
test_it="""

testing/test_warnings.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def foo():
3838
return str(test_file)
3939

4040

41-
@pytest.mark.filterwarnings("default")
41+
@pytest.mark.filterwarnings("default::UserWarning", "default::RuntimeWarning")
4242
def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None:
4343
"""Check that the warnings section is displayed."""
4444
result = pytester.runpytest(pyfile_with_warnings)
@@ -55,7 +55,7 @@ def test_normal_flow(pytester: Pytester, pyfile_with_warnings) -> None:
5555
)
5656

5757

58-
@pytest.mark.filterwarnings("always")
58+
@pytest.mark.filterwarnings("always::UserWarning")
5959
def test_setup_teardown_warnings(pytester: Pytester) -> None:
6060
pytester.makepyfile(
6161
"""
@@ -123,7 +123,7 @@ def test_ignore(pytester: Pytester, pyfile_with_warnings, method) -> None:
123123
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
124124

125125

126-
@pytest.mark.filterwarnings("always")
126+
@pytest.mark.filterwarnings("always::UserWarning")
127127
def test_unicode(pytester: Pytester) -> None:
128128
pytester.makepyfile(
129129
"""
@@ -182,7 +182,7 @@ def test_filterwarnings_mark(pytester: Pytester, default_config) -> None:
182182
pytester.makeini(
183183
"""
184184
[pytest]
185-
filterwarnings = always
185+
filterwarnings = always::RuntimeWarning
186186
"""
187187
)
188188
pytester.makepyfile(
@@ -202,7 +202,9 @@ def test_show_warning():
202202
warnings.warn(RuntimeWarning())
203203
"""
204204
)
205-
result = pytester.runpytest("-W always" if default_config == "cmdline" else "")
205+
result = pytester.runpytest(
206+
"-W always::RuntimeWarning" if default_config == "cmdline" else ""
207+
)
206208
result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warning in *"])
207209

208210

@@ -217,7 +219,7 @@ def test():
217219
warnings.warn(UserWarning(1, 'foo'))
218220
"""
219221
)
220-
result = pytester.runpytest("-W", "always")
222+
result = pytester.runpytest("-W", "always::UserWarning")
221223
result.stdout.fnmatch_lines(["*= 1 passed, 1 warning in *"])
222224

223225

@@ -236,7 +238,7 @@ def test_func():
236238
assert result.ret == 0
237239

238240

239-
@pytest.mark.filterwarnings("always")
241+
@pytest.mark.filterwarnings("always::UserWarning")
240242
def test_warning_captured_hook(pytester: Pytester) -> None:
241243
pytester.makeconftest(
242244
"""
@@ -297,7 +299,7 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
297299
assert collected_result[3] is None, str(collected)
298300

299301

300-
@pytest.mark.filterwarnings("always")
302+
@pytest.mark.filterwarnings("always::UserWarning")
301303
def test_collection_warnings(pytester: Pytester) -> None:
302304
"""Check that we also capture warnings issued during test collection (#3251)."""
303305
pytester.makepyfile(
@@ -321,7 +323,7 @@ def test_foo():
321323
)
322324

323325

324-
@pytest.mark.filterwarnings("always")
326+
@pytest.mark.filterwarnings("always::UserWarning")
325327
def test_mark_regex_escape(pytester: Pytester) -> None:
326328
"""@pytest.mark.filterwarnings should not try to escape regex characters (#3936)"""
327329
pytester.makepyfile(
@@ -337,7 +339,7 @@ def test_foo():
337339
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()
338340

339341

340-
@pytest.mark.filterwarnings("default")
342+
@pytest.mark.filterwarnings("default::pytest.PytestWarning")
341343
@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
342344
def test_hide_pytest_internal_warnings(
343345
pytester: Pytester, ignore_pytest_warnings
@@ -387,7 +389,7 @@ def test_option_precedence_cmdline_over_ini(
387389
pytester.makeini(
388390
"""
389391
[pytest]
390-
filterwarnings = error
392+
filterwarnings = error::UserWarning
391393
"""
392394
)
393395
pytester.makepyfile(
@@ -581,8 +583,7 @@ def test_warnings_checker_twice() -> None:
581583
warnings.warn("Message B", UserWarning)
582584

583585

584-
@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
585-
@pytest.mark.filterwarnings("always")
586+
@pytest.mark.filterwarnings("always::UserWarning")
586587
def test_group_warnings_by_message(pytester: Pytester) -> None:
587588
pytester.copy_example("warnings/test_group_warnings_by_message.py")
588589
result = pytester.runpytest()
@@ -613,8 +614,7 @@ def test_group_warnings_by_message(pytester: Pytester) -> None:
613614
)
614615

615616

616-
@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
617-
@pytest.mark.filterwarnings("always")
617+
@pytest.mark.filterwarnings("always::UserWarning")
618618
def test_group_warnings_by_message_summary(pytester: Pytester) -> None:
619619
pytester.copy_example("warnings/test_group_warnings_by_message_summary")
620620
pytester.syspathinsert()

0 commit comments

Comments
 (0)