Merge pull request #5925 from asottile/fix_resource_warning_again_5088
Fix spurious ResourceWarning stderr in testsuite again
This commit is contained in:
commit
3fada8c8ee
|
@ -567,9 +567,19 @@ def test_pytest_exit_msg(testdir):
|
||||||
result.stderr.fnmatch_lines(["Exit: oh noes"])
|
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):
|
def test_pytest_exit_returncode(testdir):
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""\
|
||||||
import pytest
|
import pytest
|
||||||
def test_foo():
|
def test_foo():
|
||||||
pytest.exit("some exit msg", 99)
|
pytest.exit("some exit msg", 99)
|
||||||
|
@ -577,19 +587,13 @@ def test_pytest_exit_returncode(testdir):
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(["*! *Exit: some exit msg !*"])
|
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 _strip_resource_warnings(result.stderr.lines) == [""]
|
||||||
assert [
|
|
||||||
x
|
|
||||||
for x in result.stderr.lines
|
|
||||||
if not x.startswith("Exception ignored in:")
|
|
||||||
and not x.startswith("ResourceWarning")
|
|
||||||
] == [""]
|
|
||||||
assert result.ret == 99
|
assert result.ret == 99
|
||||||
|
|
||||||
# It prints to stderr also in case of exit during pytest_sessionstart.
|
# It prints to stderr also in case of exit during pytest_sessionstart.
|
||||||
testdir.makeconftest(
|
testdir.makeconftest(
|
||||||
"""
|
"""\
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
def pytest_sessionstart():
|
def pytest_sessionstart():
|
||||||
|
@ -598,7 +602,10 @@ def test_pytest_exit_returncode(testdir):
|
||||||
)
|
)
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(["*! *Exit: during_sessionstart !*"])
|
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
|
assert result.ret == 98
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue