Skip to content

Commit c0ffee4

Browse files
committedApr 8, 2024··
Add test
Weather: broken clouds
1 parent 95fa59f commit c0ffee4

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed
 

‎testing/test_collection.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import sys
77
import tempfile
88
import textwrap
9-
from typing import List
9+
from typing import List, Type
1010

1111
from _pytest.assertion.util import running_on_ci
1212
from _pytest.config import ExitCode
@@ -1857,3 +1857,23 @@ def test_do_not_collect_symlink_siblings(
18571857
# Ensure we collect it only once if we pass the symlinked directory.
18581858
result = pytester.runpytest(symlink_path, "-sv")
18591859
result.assert_outcomes(passed=1)
1860+
1861+
1862+
@pytest.mark.parametrize("exception_class", (KeyboardInterrupt, SystemExit))
1863+
def test_respect_system_exceptions(
1864+
pytester: Pytester, exception_class: Type[BaseException]
1865+
):
1866+
ensure_file(pytester.path / "test_bar.py").write_text(
1867+
"raise SystemError()", encoding="UTF-8"
1868+
)
1869+
ensure_file(pytester.path / "test_baz.py").write_text(
1870+
f"raise {exception_class.__name__}()", encoding="UTF-8"
1871+
)
1872+
ensure_file(pytester.path / "test_foo.py").write_text(
1873+
"raise NotImplementedError()", encoding="UTF-8"
1874+
)
1875+
1876+
result = pytester.runpytest_subprocess()
1877+
result.stderr.fnmatch_lines(["*SystemError*"])
1878+
result.stderr.fnmatch_lines([f"*{exception_class.__name__}*"])
1879+
result.stderr.no_fnmatch_line("*NotImplementedError*")

0 commit comments

Comments
 (0)