@@ -567,29 +567,33 @@ def pytest_configure(config):
567
567
result .stderr .fnmatch_lines (["Exit: oh noes" ])
568
568
569
569
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
+
570
580
def test_pytest_exit_returncode (testdir ):
571
581
testdir .makepyfile (
572
- """
582
+ """\
573
583
import pytest
574
584
def test_foo():
575
585
pytest.exit("some exit msg", 99)
576
586
"""
577
587
)
578
588
result = testdir .runpytest ()
579
589
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 ) == ["" ]
588
592
assert result .ret == 99
589
593
590
594
# It prints to stderr also in case of exit during pytest_sessionstart.
591
595
testdir .makeconftest (
592
- """
596
+ """\
593
597
import pytest
594
598
595
599
def pytest_sessionstart():
@@ -598,7 +602,10 @@ def pytest_sessionstart():
598
602
)
599
603
result = testdir .runpytest ()
600
604
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
+ ]
602
609
assert result .ret == 98
603
610
604
611
0 commit comments