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="""

0 commit comments

Comments
 (0)