From c0ffee46f385fda5140ba63f58e442a41fd16622 Mon Sep 17 00:00:00 2001 From: Anita Hammer <166057949+anitahammer@users.noreply.github.com> Date: Mon, 8 Apr 2024 01:24:54 +0100 Subject: [PATCH] Add test Weather: broken clouds --- testing/test_collection.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/testing/test_collection.py b/testing/test_collection.py index 1491ec85990..b50bd0baebe 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -6,7 +6,7 @@ import sys import tempfile import textwrap -from typing import List +from typing import List, Type from _pytest.assertion.util import running_on_ci from _pytest.config import ExitCode @@ -1857,3 +1857,23 @@ def test_do_not_collect_symlink_siblings( # Ensure we collect it only once if we pass the symlinked directory. result = pytester.runpytest(symlink_path, "-sv") result.assert_outcomes(passed=1) + + +@pytest.mark.parametrize("exception_class", (KeyboardInterrupt, SystemExit)) +def test_respect_system_exceptions( + pytester: Pytester, exception_class: Type[BaseException] +): + ensure_file(pytester.path / "test_bar.py").write_text( + "raise SystemError()", encoding="UTF-8" + ) + ensure_file(pytester.path / "test_baz.py").write_text( + f"raise {exception_class.__name__}()", encoding="UTF-8" + ) + ensure_file(pytester.path / "test_foo.py").write_text( + "raise NotImplementedError()", encoding="UTF-8" + ) + + result = pytester.runpytest_subprocess() + result.stderr.fnmatch_lines(["*SystemError*"]) + result.stderr.fnmatch_lines([f"*{exception_class.__name__}*"]) + result.stderr.no_fnmatch_line("*NotImplementedError*")