From eaa05531eddd70ef30ad0771c98bb47cfa6fc710 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 1 Oct 2019 13:24:23 -0700 Subject: [PATCH 1/2] Add test to ensure _pytest is warning-clean on import --- testing/test_meta.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 testing/test_meta.py diff --git a/testing/test_meta.py b/testing/test_meta.py new file mode 100644 index 000000000..7aa100e6e --- /dev/null +++ b/testing/test_meta.py @@ -0,0 +1,28 @@ +import pkgutil +import subprocess +import sys + +import _pytest +import pytest + + +def _modules(): + return sorted( + n + for _, n, _ in pkgutil.walk_packages( + _pytest.__path__, prefix=_pytest.__name__ + "." + ) + ) + + +@pytest.mark.parametrize("module", _modules()) +def test_no_warnings(module): + # fmt: off + subprocess.check_call(( + sys.executable, + "-W", "error", + # https://github.com/pytest-dev/pytest/issues/5901 + "-W", "ignore:The usage of `cmp` is deprecated and will be removed on or after 2021-06-01. Please use `eq` and `order` instead.:DeprecationWarning", # noqa: E501 + "-c", "import {}".format(module), + )) + # fmt: on From 19eb0590f136619672255555f06dcfc8319cce2d Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 6 Oct 2019 19:11:33 -0700 Subject: [PATCH 2/2] Fix spurious ResourceWarning stderr in testsuite again --- testing/test_runner.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/testing/test_runner.py b/testing/test_runner.py index 82e413518..63a94d258 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -567,9 +567,19 @@ def test_pytest_exit_msg(testdir): result.stderr.fnmatch_lines(["Exit: oh noes"]) +def _strip_resource_warnings(lines): + # Assert no output on stderr, except for unreliable ResourceWarnings. + # (https://github.com/pytest-dev/pytest/issues/5088) + return [ + x + for x in lines + if not x.startswith(("Exception ignored in:", "ResourceWarning")) + ] + + def test_pytest_exit_returncode(testdir): testdir.makepyfile( - """ + """\ import pytest def test_foo(): pytest.exit("some exit msg", 99) @@ -577,19 +587,13 @@ def test_pytest_exit_returncode(testdir): ) result = testdir.runpytest() result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"]) - # Assert no output on stderr, except for unreliable ResourceWarnings. - # (https://github.com/pytest-dev/pytest/issues/5088) - assert [ - x - for x in result.stderr.lines - if not x.startswith("Exception ignored in:") - and not x.startswith("ResourceWarning") - ] == [""] + + assert _strip_resource_warnings(result.stderr.lines) == [""] assert result.ret == 99 # It prints to stderr also in case of exit during pytest_sessionstart. testdir.makeconftest( - """ + """\ import pytest def pytest_sessionstart(): @@ -598,7 +602,10 @@ def test_pytest_exit_returncode(testdir): ) result = testdir.runpytest() result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"]) - assert result.stderr.lines == ["Exit: during_sessionstart", ""] + assert _strip_resource_warnings(result.stderr.lines) == [ + "Exit: during_sessionstart", + "", + ] assert result.ret == 98