Skip to content

Commit 21c038f

Browse files
committed
Merge master into features
2 parents fca462c + 3fada8c commit 21c038f

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

testing/test_meta.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pkgutil
2+
import subprocess
3+
import sys
4+
5+
import _pytest
6+
import pytest
7+
8+
9+
def _modules():
10+
return sorted(
11+
n
12+
for _, n, _ in pkgutil.walk_packages(
13+
_pytest.__path__, prefix=_pytest.__name__ + "."
14+
)
15+
)
16+
17+
18+
@pytest.mark.parametrize("module", _modules())
19+
def test_no_warnings(module):
20+
# fmt: off
21+
subprocess.check_call((
22+
sys.executable,
23+
"-W", "error",
24+
# https://github.com/pytest-dev/pytest/issues/5901
25+
"-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
26+
"-c", "import {}".format(module),
27+
))
28+
# fmt: on

testing/test_runner.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -567,29 +567,33 @@ def pytest_configure(config):
567567
result.stderr.fnmatch_lines(["Exit: oh noes"])
568568

569569

570+
def _strip_resource_warnings(lines):
571+
# Assert no output on stderr, except for unreliable ResourceWarnings.
572+
# (https://github.com/pytest-dev/pytest/issues/5088)
573+
return [
574+
x
575+
for x in lines
576+
if not x.startswith(("Exception ignored in:", "ResourceWarning"))
577+
]
578+
579+
570580
def test_pytest_exit_returncode(testdir):
571581
testdir.makepyfile(
572-
"""
582+
"""\
573583
import pytest
574584
def test_foo():
575585
pytest.exit("some exit msg", 99)
576586
"""
577587
)
578588
result = testdir.runpytest()
579589
result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"])
580-
# Assert no output on stderr, except for unreliable ResourceWarnings.
581-
# (https://github.com/pytest-dev/pytest/issues/5088)
582-
assert [
583-
x
584-
for x in result.stderr.lines
585-
if not x.startswith("Exception ignored in:")
586-
and not x.startswith("ResourceWarning")
587-
] == [""]
590+
591+
assert _strip_resource_warnings(result.stderr.lines) == [""]
588592
assert result.ret == 99
589593

590594
# It prints to stderr also in case of exit during pytest_sessionstart.
591595
testdir.makeconftest(
592-
"""
596+
"""\
593597
import pytest
594598
595599
def pytest_sessionstart():
@@ -598,7 +602,10 @@ def pytest_sessionstart():
598602
)
599603
result = testdir.runpytest()
600604
result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"])
601-
assert result.stderr.lines == ["Exit: during_sessionstart", ""]
605+
assert _strip_resource_warnings(result.stderr.lines) == [
606+
"Exit: during_sessionstart",
607+
"",
608+
]
602609
assert result.ret == 98
603610

604611

0 commit comments

Comments
 (0)