Skip to content

Commit

Permalink
Merge pull request pytest-dev#8555 from The-Compiler/py310-fix
Browse files Browse the repository at this point in the history
Fix Python 3.10 test issues
  • Loading branch information
The-Compiler committed May 5, 2021
2 parents 385988c + 3825992 commit adc1974
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 43 deletions.
8 changes: 8 additions & 0 deletions pyproject.toml
Expand Up @@ -42,6 +42,14 @@ filterwarnings = [
"default:invalid escape sequence:DeprecationWarning",
# ignore use of unregistered marks, because we use many to test the implementation
"ignore::_pytest.warning_types.PytestUnknownMarkWarning",
# https://github.com/benjaminp/six/issues/341
"ignore:_SixMetaPathImporter\\.exec_module\\(\\) not found; falling back to load_module\\(\\):ImportWarning",
# https://github.com/benjaminp/six/pull/352
"ignore:_SixMetaPathImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
# https://github.com/pypa/setuptools/pull/2517
"ignore:VendorImporter\\.find_spec\\(\\) not found; falling back to find_module\\(\\):ImportWarning",
# https://github.com/pytest-dev/execnet/pull/127
"ignore:isSet\\(\\) is deprecated, use is_set\\(\\) instead:DeprecationWarning",
]
pytester_example_dir = "testing/example_scripts"
markers = [
Expand Down
4 changes: 2 additions & 2 deletions testing/acceptance_test.py
Expand Up @@ -1173,7 +1173,7 @@ def test_usage_error_code(pytester: Pytester) -> None:
assert result.ret == ExitCode.USAGE_ERROR


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


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledCoroutineWarning")
def test_warn_on_async_gen_function(pytester: Pytester) -> None:
pytester.makepyfile(
test_async="""
Expand Down
2 changes: 1 addition & 1 deletion testing/python/collect.py
Expand Up @@ -1237,7 +1237,7 @@ class Test(object):
assert result.ret == ExitCode.NO_TESTS_COLLECTED


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestCollectionWarning")
def test_dont_collect_non_function_callable(pytester: Pytester) -> None:
"""Test for issue https://github.com/pytest-dev/pytest/issues/331
Expand Down
5 changes: 4 additions & 1 deletion testing/python/metafunc.py
Expand Up @@ -448,7 +448,10 @@ def test_idmaker_enum(self) -> None:
enum = pytest.importorskip("enum")
e = enum.Enum("Foo", "one, two")
result = idmaker(("a", "b"), [pytest.param(e.one, e.two)])
assert result == ["Foo.one-Foo.two"]
if sys.version_info[:2] >= (3, 10):
assert result == ["one-two"]
else:
assert result == ["Foo.one-Foo.two"]

def test_idmaker_idfn(self) -> None:
"""#351"""
Expand Down
2 changes: 1 addition & 1 deletion testing/test_collection.py
Expand Up @@ -1225,7 +1225,7 @@ def test_collect_symlink_dir(pytester: Pytester) -> None:
"""A symlinked directory is collected."""
dir = pytester.mkdir("dir")
dir.joinpath("test_it.py").write_text("def test_it(): pass", "utf-8")
pytester.path.joinpath("symlink_dir").symlink_to(dir)
symlink_or_skip(pytester.path.joinpath("symlink_dir"), dir)
result = pytester.runpytest()
result.assert_outcomes(passed=2)

Expand Down
2 changes: 1 addition & 1 deletion testing/test_config.py
Expand Up @@ -290,7 +290,7 @@ def test_silence_unknown_key_warning(self, pytester: Pytester) -> None:
result = pytester.runpytest()
result.stdout.no_fnmatch_line("*PytestConfigWarning*")

@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestConfigWarning")
def test_disable_warnings_plugin_disables_config_warnings(
self, pytester: Pytester
) -> None:
Expand Down
14 changes: 10 additions & 4 deletions testing/test_pytester.py
Expand Up @@ -744,10 +744,16 @@ def test_run_result_repr() -> None:

# known exit code
r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5)
assert (
repr(r) == "<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
" len(stderr.lines)=4 duration=0.50s>"
)
if sys.version_info[:2] >= (3, 10):
assert repr(r) == (
"<RunResult ret=TESTS_FAILED len(stdout.lines)=3"
" len(stderr.lines)=4 duration=0.50s>"
)
else:
assert repr(r) == (
"<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
" len(stderr.lines)=4 duration=0.50s>"
)

# unknown exit code: just the number
r = pytester_mod.RunResult(99, outlines, errlines, duration=0.5)
Expand Down
33 changes: 23 additions & 10 deletions testing/test_skipping.py
Expand Up @@ -1143,21 +1143,34 @@ def test_func():
pypy_version_info = getattr(sys, "pypy_version_info", None)
if pypy_version_info is not None and pypy_version_info < (6,):
markline = markline[5:]
elif sys.version_info[:2] >= (3, 10):
markline = markline[11:]
elif sys.version_info >= (3, 8) or hasattr(sys, "pypy_version_info"):
markline = markline[4:]
result.stdout.fnmatch_lines(
[

if sys.version_info[:2] >= (3, 10):
expected = [
"*ERROR*test_nameerror*",
"*evaluating*skipif*condition*",
"*asd*",
"*ERROR*test_syntax*",
"*evaluating*xfail*condition*",
" syntax error",
markline,
"SyntaxError: invalid syntax",
"*1 pass*2 errors*",
"",
"During handling of the above exception, another exception occurred:",
]
)
else:
expected = [
"*ERROR*test_nameerror*",
]

expected += [
"*evaluating*skipif*condition*",
"*asd*",
"*ERROR*test_syntax*",
"*evaluating*xfail*condition*",
" syntax error",
markline,
"SyntaxError: invalid syntax",
"*1 pass*2 errors*",
]
result.stdout.fnmatch_lines(expected)


def test_xfail_skipif_with_globals(pytester: Pytester) -> None:
Expand Down
4 changes: 2 additions & 2 deletions testing/test_terminal.py
Expand Up @@ -1618,7 +1618,7 @@ def pytest_terminal_summary(terminalreporter, exitstatus):
)


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


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::UserWarning")
def test_terminal_summary_warnings_header_once(pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down
6 changes: 3 additions & 3 deletions testing/test_threadexception.py
Expand Up @@ -8,7 +8,7 @@
pytest.skip("threadexception plugin needs Python>=3.8", allow_module_level=True)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
def test_unhandled_thread_exception(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down Expand Up @@ -42,7 +42,7 @@ def test_2(): pass
)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
def test_unhandled_thread_exception_in_setup(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_2(): pass
)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnhandledThreadExceptionWarning")
def test_unhandled_thread_exception_in_teardown(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down
6 changes: 3 additions & 3 deletions testing/test_unraisableexception.py
Expand Up @@ -8,7 +8,7 @@
pytest.skip("unraisableexception plugin needs Python>=3.8", allow_module_level=True)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
def test_unraisable(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down Expand Up @@ -40,7 +40,7 @@ def test_2(): pass
)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
def test_unraisable_in_setup(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_2(): pass
)


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestUnraisableExceptionWarning")
def test_unraisable_in_teardown(pytester: Pytester) -> None:
pytester.makepyfile(
test_it="""
Expand Down
30 changes: 15 additions & 15 deletions testing/test_warnings.py
Expand Up @@ -38,7 +38,7 @@ def foo():
return str(test_file)


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


@pytest.mark.filterwarnings("always")
@pytest.mark.filterwarnings("always::UserWarning")
def test_setup_teardown_warnings(pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_ignore(pytester: Pytester, pyfile_with_warnings, method) -> None:
assert WARNINGS_SUMMARY_HEADER not in result.stdout.str()


@pytest.mark.filterwarnings("always")
@pytest.mark.filterwarnings("always::UserWarning")
def test_unicode(pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_filterwarnings_mark(pytester: Pytester, default_config) -> None:
pytester.makeini(
"""
[pytest]
filterwarnings = always
filterwarnings = always::RuntimeWarning
"""
)
pytester.makepyfile(
Expand All @@ -202,7 +202,9 @@ def test_show_warning():
warnings.warn(RuntimeWarning())
"""
)
result = pytester.runpytest("-W always" if default_config == "cmdline" else "")
result = pytester.runpytest(
"-W always::RuntimeWarning" if default_config == "cmdline" else ""
)
result.stdout.fnmatch_lines(["*= 1 failed, 2 passed, 1 warning in *"])


Expand All @@ -217,7 +219,7 @@ def test():
warnings.warn(UserWarning(1, 'foo'))
"""
)
result = pytester.runpytest("-W", "always")
result = pytester.runpytest("-W", "always::UserWarning")
result.stdout.fnmatch_lines(["*= 1 passed, 1 warning in *"])


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


@pytest.mark.filterwarnings("always")
@pytest.mark.filterwarnings("always::UserWarning")
def test_warning_captured_hook(pytester: Pytester) -> None:
pytester.makeconftest(
"""
Expand Down Expand Up @@ -297,7 +299,7 @@ def pytest_warning_recorded(self, warning_message, when, nodeid, location):
assert collected_result[3] is None, str(collected)


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


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


@pytest.mark.filterwarnings("default")
@pytest.mark.filterwarnings("default::pytest.PytestWarning")
@pytest.mark.parametrize("ignore_pytest_warnings", ["no", "ini", "cmdline"])
def test_hide_pytest_internal_warnings(
pytester: Pytester, ignore_pytest_warnings
Expand Down Expand Up @@ -387,7 +389,7 @@ def test_option_precedence_cmdline_over_ini(
pytester.makeini(
"""
[pytest]
filterwarnings = error
filterwarnings = error::UserWarning
"""
)
pytester.makepyfile(
Expand Down Expand Up @@ -581,8 +583,7 @@ def test_warnings_checker_twice() -> None:
warnings.warn("Message B", UserWarning)


@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
@pytest.mark.filterwarnings("always")
@pytest.mark.filterwarnings("always::UserWarning")
def test_group_warnings_by_message(pytester: Pytester) -> None:
pytester.copy_example("warnings/test_group_warnings_by_message.py")
result = pytester.runpytest()
Expand Down Expand Up @@ -613,8 +614,7 @@ def test_group_warnings_by_message(pytester: Pytester) -> None:
)


@pytest.mark.filterwarnings("ignore::pytest.PytestExperimentalApiWarning")
@pytest.mark.filterwarnings("always")
@pytest.mark.filterwarnings("always::UserWarning")
def test_group_warnings_by_message_summary(pytester: Pytester) -> None:
pytester.copy_example("warnings/test_group_warnings_by_message_summary")
pytester.syspathinsert()
Expand Down

0 comments on commit adc1974

Please sign in to comment.