Skip to content

Commit 043ed55

Browse files
authored
Migrate from testdir to pytester
1 parent b2e7b9d commit 043ed55

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

testing/test_faulthandler.py

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

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

5-
6-
def test_enabled(testdir):
6+
def test_enabled(pytester: Pytester) -> None:
77
"""Test single crashing test displays a traceback."""
8-
testdir.makepyfile(
8+
pytester.makepyfile(
99
"""
1010
import faulthandler
1111
def test_crash():
1212
faulthandler._sigabrt()
1313
"""
1414
)
15-
result = testdir.runpytest_subprocess()
15+
result = pytester.runpytest_subprocess()
1616
result.stderr.fnmatch_lines(["*Fatal Python error*"])
1717
assert result.ret != 0
1818

1919

20-
def test_crash_near_exit(testdir):
20+
def test_crash_near_exit(pytester: Pytester) -> None:
2121
"""Test that fault handler displays crashes that happen even after
2222
pytest is exiting (for example, when the interpreter is shutting down)."""
23-
testdir.makepyfile(
23+
pytester.makepyfile(
2424
"""
2525
import faulthandler
2626
import atexit
2727
def test_ok():
2828
atexit.register(faulthandler._sigabrt)
2929
"""
3030
)
31-
result = testdir.runpytest_subprocess()
31+
result = pytester.runpytest_subprocess()
3232
result.stderr.fnmatch_lines(["*Fatal Python error*"])
3333
assert result.ret != 0
3434

3535

36-
def test_disabled(testdir):
36+
def test_disabled(pytester: Pytester) -> None:
3737
"""Test option to disable fault handler in the command line."""
38-
testdir.makepyfile(
38+
pytester.makepyfile(
3939
"""
4040
import faulthandler
4141
def test_disabled():
4242
assert not faulthandler.is_enabled()
4343
"""
4444
)
45-
result = testdir.runpytest_subprocess("-p", "no:faulthandler")
45+
result = pytester.runpytest_subprocess("-p", "no:faulthandler")
4646
result.stdout.fnmatch_lines(["*1 passed*"])
4747
assert result.ret == 0
4848

@@ -56,27 +56,27 @@ def test_disabled():
5656
False,
5757
],
5858
)
59-
def test_timeout(testdir, enabled: bool) -> None:
59+
def test_timeout(pytester: Pytester, enabled: bool) -> None:
6060
"""Test option to dump tracebacks after a certain timeout.
6161
6262
If faulthandler is disabled, no traceback will be dumped.
6363
"""
64-
testdir.makepyfile(
64+
pytester.makepyfile(
6565
"""
6666
import os, time
6767
def test_timeout():
6868
time.sleep(1 if "CI" in os.environ else 0.1)
6969
"""
7070
)
71-
testdir.makeini(
71+
pytester.makeini(
7272
"""
7373
[pytest]
7474
faulthandler_timeout = 0.01
7575
"""
7676
)
7777
args = ["-p", "no:faulthandler"] if not enabled else []
7878

79-
result = testdir.runpytest_subprocess(*args)
79+
result = pytester.runpytest_subprocess(*args)
8080
tb_output = "most recent call first"
8181
if enabled:
8282
result.stderr.fnmatch_lines(["*%s*" % tb_output])
@@ -108,21 +108,21 @@ def test_cancel_timeout_on_hook(monkeypatch, hook_name):
108108

109109

110110
@pytest.mark.parametrize("faulthandler_timeout", [0, 2])
111-
def test_already_initialized(faulthandler_timeout, testdir):
111+
def test_already_initialized(faulthandler_timeout, pytester: Pytester):
112112
"""Test for faulthandler being initialized earlier than pytest (#6575)."""
113-
testdir.makepyfile(
113+
pytester.makepyfile(
114114
"""
115115
def test():
116116
import faulthandler
117117
assert faulthandler.is_enabled()
118118
"""
119119
)
120-
result = testdir.run(
120+
result = pytester.run(
121121
sys.executable,
122122
"-X",
123123
"faulthandler",
124124
"-mpytest",
125-
testdir.tmpdir,
125+
pytester.tmpdir,
126126
"-o",
127127
f"faulthandler_timeout={faulthandler_timeout}",
128128
)

0 commit comments

Comments
 (0)