Skip to content

Commit 3fada8c

Browse files
authored
Merge pull request #5925 from asottile/fix_resource_warning_again_5088
Fix spurious ResourceWarning stderr in testsuite again
2 parents 271dc7f + 19eb059 commit 3fada8c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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)