Skip to content

Commit ea3c0aa

Browse files
authored
Merge pull request #8019 from JosiasAurel/mypytester-change-01
Migrate from testdir to pytester
2 parents 843bca8 + fa148ea commit ea3c0aa

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

testing/test_faulthandler.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
import sys
22

33
import pytest
4+
from _pytest.pytester import Pytester
45

56

6-
def test_enabled(testdir):
7+
def test_enabled(pytester: Pytester) -> None:
78
"""Test single crashing test displays a traceback."""
8-
testdir.makepyfile(
9+
pytester.makepyfile(
910
"""
1011
import faulthandler
1112
def test_crash():
1213
faulthandler._sigabrt()
1314
"""
1415
)
15-
result = testdir.runpytest_subprocess()
16+
result = pytester.runpytest_subprocess()
1617
result.stderr.fnmatch_lines(["*Fatal Python error*"])
1718
assert result.ret != 0
1819

1920

20-
def test_crash_near_exit(testdir):
21+
def test_crash_near_exit(pytester: Pytester) -> None:
2122
"""Test that fault handler displays crashes that happen even after
2223
pytest is exiting (for example, when the interpreter is shutting down)."""
23-
testdir.makepyfile(
24+
pytester.makepyfile(
2425
"""
2526
import faulthandler
2627
import atexit
2728
def test_ok():
2829
atexit.register(faulthandler._sigabrt)
2930
"""
3031
)
31-
result = testdir.runpytest_subprocess()
32+
result = pytester.runpytest_subprocess()
3233
result.stderr.fnmatch_lines(["*Fatal Python error*"])
3334
assert result.ret != 0
3435

3536

36-
def test_disabled(testdir):
37+
def test_disabled(pytester: Pytester) -> None:
3738
"""Test option to disable fault handler in the command line."""
38-
testdir.makepyfile(
39+
pytester.makepyfile(
3940
"""
4041
import faulthandler
4142
def test_disabled():
4243
assert not faulthandler.is_enabled()
4344
"""
4445
)
45-
result = testdir.runpytest_subprocess("-p", "no:faulthandler")
46+
result = pytester.runpytest_subprocess("-p", "no:faulthandler")
4647
result.stdout.fnmatch_lines(["*1 passed*"])
4748
assert result.ret == 0
4849

@@ -56,27 +57,27 @@ def test_disabled():
5657
False,
5758
],
5859
)
59-
def test_timeout(testdir, enabled: bool) -> None:
60+
def test_timeout(pytester: Pytester, enabled: bool) -> None:
6061
"""Test option to dump tracebacks after a certain timeout.
6162
6263
If faulthandler is disabled, no traceback will be dumped.
6364
"""
64-
testdir.makepyfile(
65+
pytester.makepyfile(
6566
"""
6667
import os, time
6768
def test_timeout():
6869
time.sleep(1 if "CI" in os.environ else 0.1)
6970
"""
7071
)
71-
testdir.makeini(
72+
pytester.makeini(
7273
"""
7374
[pytest]
7475
faulthandler_timeout = 0.01
7576
"""
7677
)
7778
args = ["-p", "no:faulthandler"] if not enabled else []
7879

79-
result = testdir.runpytest_subprocess(*args)
80+
result = pytester.runpytest_subprocess(*args)
8081
tb_output = "most recent call first"
8182
if enabled:
8283
result.stderr.fnmatch_lines(["*%s*" % tb_output])
@@ -87,7 +88,7 @@ def test_timeout():
8788

8889

8990
@pytest.mark.parametrize("hook_name", ["pytest_enter_pdb", "pytest_exception_interact"])
90-
def test_cancel_timeout_on_hook(monkeypatch, hook_name):
91+
def test_cancel_timeout_on_hook(monkeypatch, hook_name) -> None:
9192
"""Make sure that we are cancelling any scheduled traceback dumping due
9293
to timeout before entering pdb (pytest-dev/pytest-faulthandler#12) or any
9394
other interactive exception (pytest-dev/pytest-faulthandler#14)."""
@@ -108,21 +109,21 @@ def test_cancel_timeout_on_hook(monkeypatch, hook_name):
108109

109110

110111
@pytest.mark.parametrize("faulthandler_timeout", [0, 2])
111-
def test_already_initialized(faulthandler_timeout, testdir):
112+
def test_already_initialized(faulthandler_timeout: int, pytester: Pytester) -> None:
112113
"""Test for faulthandler being initialized earlier than pytest (#6575)."""
113-
testdir.makepyfile(
114+
pytester.makepyfile(
114115
"""
115116
def test():
116117
import faulthandler
117118
assert faulthandler.is_enabled()
118119
"""
119120
)
120-
result = testdir.run(
121+
result = pytester.run(
121122
sys.executable,
122123
"-X",
123124
"faulthandler",
124125
"-mpytest",
125-
testdir.tmpdir,
126+
pytester.path,
126127
"-o",
127128
f"faulthandler_timeout={faulthandler_timeout}",
128129
)

0 commit comments

Comments
 (0)