Skip to content

Commit

Permalink
Merge pull request pytest-dev#5925 from asottile/fix_resource_warning…
Browse files Browse the repository at this point in the history
…_again_5088

Fix spurious ResourceWarning stderr in testsuite again
  • Loading branch information
Anthony Sottile committed Oct 7, 2019
2 parents 271dc7f + 19eb059 commit 3fada8c
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,29 +567,33 @@ def pytest_configure(config):
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)
"""
)
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():
Expand All @@ -598,7 +602,10 @@ def pytest_sessionstart():
)
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


Expand Down

0 comments on commit 3fada8c

Please sign in to comment.