|
7 | 7 | import tempfile |
8 | 8 | import textwrap |
9 | 9 | from typing import List |
| 10 | +from typing import Type |
10 | 11 |
|
11 | 12 | from _pytest.assertion.util import running_on_ci |
12 | 13 | from _pytest.config import ExitCode |
@@ -1856,3 +1857,33 @@ def test_do_not_collect_symlink_siblings( |
1856 | 1857 | # Ensure we collect it only once if we pass the symlinked directory. |
1857 | 1858 | result = pytester.runpytest(symlink_path, "-sv") |
1858 | 1859 | result.assert_outcomes(passed=1) |
| 1860 | + |
| 1861 | + |
| 1862 | +@pytest.mark.parametrize( |
| 1863 | + "exception_class, msg", |
| 1864 | + [ |
| 1865 | + (KeyboardInterrupt, "*!!! KeyboardInterrupt !!!*"), |
| 1866 | + (SystemExit, "INTERNALERROR> SystemExit"), |
| 1867 | + ], |
| 1868 | +) |
| 1869 | +def test_respect_system_exceptions( |
| 1870 | + pytester: Pytester, |
| 1871 | + exception_class: Type[BaseException], |
| 1872 | + msg: str, |
| 1873 | +): |
| 1874 | + head = "Before exception" |
| 1875 | + tail = "After exception" |
| 1876 | + ensure_file(pytester.path / "test_eggs.py").write_text( |
| 1877 | + f"print('{head}')", encoding="UTF-8" |
| 1878 | + ) |
| 1879 | + ensure_file(pytester.path / "test_ham.py").write_text( |
| 1880 | + f"raise {exception_class.__name__}()", encoding="UTF-8" |
| 1881 | + ) |
| 1882 | + ensure_file(pytester.path / "test_spam.py").write_text( |
| 1883 | + f"print('{tail}')", encoding="UTF-8" |
| 1884 | + ) |
| 1885 | + |
| 1886 | + result = pytester.runpytest_subprocess("-s") |
| 1887 | + result.stdout.fnmatch_lines([f"*{head}*"]) |
| 1888 | + result.stdout.fnmatch_lines([msg]) |
| 1889 | + result.stdout.no_fnmatch_line(f"*{tail}*") |
0 commit comments