From 043ed55056ff858fc2f28f0f9239843b7085b66d Mon Sep 17 00:00:00 2001 From: Josias Aurel Date: Mon, 9 Nov 2020 18:07:34 +0100 Subject: [PATCH 1/5] Migrate from testdir to pytester --- testing/test_faulthandler.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index 4d0b32ede..fea2681ba 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -1,26 +1,26 @@ import sys import pytest +from _pytest.pytester import Pytester - -def test_enabled(testdir): +def test_enabled(pytester: Pytester) -> None: """Test single crashing test displays a traceback.""" - testdir.makepyfile( + pytester.makepyfile( """ import faulthandler def test_crash(): faulthandler._sigabrt() """ ) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() result.stderr.fnmatch_lines(["*Fatal Python error*"]) assert result.ret != 0 -def test_crash_near_exit(testdir): +def test_crash_near_exit(pytester: Pytester) -> None: """Test that fault handler displays crashes that happen even after pytest is exiting (for example, when the interpreter is shutting down).""" - testdir.makepyfile( + pytester.makepyfile( """ import faulthandler import atexit @@ -28,21 +28,21 @@ def test_crash_near_exit(testdir): atexit.register(faulthandler._sigabrt) """ ) - result = testdir.runpytest_subprocess() + result = pytester.runpytest_subprocess() result.stderr.fnmatch_lines(["*Fatal Python error*"]) assert result.ret != 0 -def test_disabled(testdir): +def test_disabled(pytester: Pytester) -> None: """Test option to disable fault handler in the command line.""" - testdir.makepyfile( + pytester.makepyfile( """ import faulthandler def test_disabled(): assert not faulthandler.is_enabled() """ ) - result = testdir.runpytest_subprocess("-p", "no:faulthandler") + result = pytester.runpytest_subprocess("-p", "no:faulthandler") result.stdout.fnmatch_lines(["*1 passed*"]) assert result.ret == 0 @@ -56,19 +56,19 @@ def test_disabled(testdir): False, ], ) -def test_timeout(testdir, enabled: bool) -> None: +def test_timeout(pytester: Pytester, enabled: bool) -> None: """Test option to dump tracebacks after a certain timeout. If faulthandler is disabled, no traceback will be dumped. """ - testdir.makepyfile( + pytester.makepyfile( """ import os, time def test_timeout(): time.sleep(1 if "CI" in os.environ else 0.1) """ ) - testdir.makeini( + pytester.makeini( """ [pytest] faulthandler_timeout = 0.01 @@ -76,7 +76,7 @@ def test_timeout(testdir, enabled: bool) -> None: ) args = ["-p", "no:faulthandler"] if not enabled else [] - result = testdir.runpytest_subprocess(*args) + result = pytester.runpytest_subprocess(*args) tb_output = "most recent call first" if enabled: result.stderr.fnmatch_lines(["*%s*" % tb_output]) @@ -108,21 +108,21 @@ def test_cancel_timeout_on_hook(monkeypatch, hook_name): @pytest.mark.parametrize("faulthandler_timeout", [0, 2]) -def test_already_initialized(faulthandler_timeout, testdir): +def test_already_initialized(faulthandler_timeout, pytester: Pytester): """Test for faulthandler being initialized earlier than pytest (#6575).""" - testdir.makepyfile( + pytester.makepyfile( """ def test(): import faulthandler assert faulthandler.is_enabled() """ ) - result = testdir.run( + result = pytester.run( sys.executable, "-X", "faulthandler", "-mpytest", - testdir.tmpdir, + pytester.tmpdir, "-o", f"faulthandler_timeout={faulthandler_timeout}", ) From 8320c071348e6d27ad789a7cbe017e01856dd835 Mon Sep 17 00:00:00 2001 From: Josias Aurel Date: Wed, 11 Nov 2020 04:45:42 +0100 Subject: [PATCH 2/5] Update testing/test_faulthandler.py Co-authored-by: Sanket Duthade --- testing/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index fea2681ba..38a3cddce 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -108,7 +108,7 @@ def test_cancel_timeout_on_hook(monkeypatch, hook_name): @pytest.mark.parametrize("faulthandler_timeout", [0, 2]) -def test_already_initialized(faulthandler_timeout, pytester: Pytester): +def test_already_initialized(faulthandler_timeout: int, pytester: Pytester) -> None: """Test for faulthandler being initialized earlier than pytest (#6575).""" pytester.makepyfile( """ From 1ed8159c7d87ee3f11d4ed428bd51f3a06d7e5d9 Mon Sep 17 00:00:00 2001 From: Josias Aurel Date: Wed, 11 Nov 2020 04:45:57 +0100 Subject: [PATCH 3/5] Update testing/test_faulthandler.py Co-authored-by: Sanket Duthade --- testing/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index 38a3cddce..7015238d8 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -122,7 +122,7 @@ def test_already_initialized(faulthandler_timeout: int, pytester: Pytester) -> N "-X", "faulthandler", "-mpytest", - pytester.tmpdir, + pytester.path, "-o", f"faulthandler_timeout={faulthandler_timeout}", ) From 06a597db14af95dbe22b87bfe1391bc22fd1857b Mon Sep 17 00:00:00 2001 From: Josias Aurel Date: Wed, 11 Nov 2020 05:02:32 +0100 Subject: [PATCH 4/5] Add type annotations --- testing/test_faulthandler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index 7015238d8..e25424fc0 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -87,7 +87,7 @@ def test_timeout(pytester: Pytester, enabled: bool) -> None: @pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"]) -def test_cancel_timeout_on_hook(monkeypatch, hook_name): +def test_cancel_timeout_on_hook(monkeypatch, hook_name) -> None: """Make sure that we are cancelling any scheduled traceback dumping due to timeout before entering pdb (pytest-dev/pytest-faulthandler#12) or any other interactive exception (pytest-dev/pytest-faulthandler#14).""" From fa148eadfe9ed1547f5a6122d9f51d0302f42c43 Mon Sep 17 00:00:00 2001 From: Josias Aurel Date: Wed, 11 Nov 2020 18:35:06 +0100 Subject: [PATCH 5/5] Update testing/test_faulthandler.py Co-authored-by: Sanket Duthade --- testing/test_faulthandler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/test_faulthandler.py b/testing/test_faulthandler.py index e25424fc0..caf39813c 100644 --- a/testing/test_faulthandler.py +++ b/testing/test_faulthandler.py @@ -3,6 +3,7 @@ import sys import pytest from _pytest.pytester import Pytester + def test_enabled(pytester: Pytester) -> None: """Test single crashing test displays a traceback.""" pytester.makepyfile(