1
1
import sys
2
2
3
3
import pytest
4
+ from _pytest .pytester import Pytester
4
5
5
6
6
- def test_enabled (testdir ) :
7
+ def test_enabled (pytester : Pytester ) -> None :
7
8
"""Test single crashing test displays a traceback."""
8
- testdir .makepyfile (
9
+ pytester .makepyfile (
9
10
"""
10
11
import faulthandler
11
12
def test_crash():
12
13
faulthandler._sigabrt()
13
14
"""
14
15
)
15
- result = testdir .runpytest_subprocess ()
16
+ result = pytester .runpytest_subprocess ()
16
17
result .stderr .fnmatch_lines (["*Fatal Python error*" ])
17
18
assert result .ret != 0
18
19
19
20
20
- def test_crash_near_exit (testdir ) :
21
+ def test_crash_near_exit (pytester : Pytester ) -> None :
21
22
"""Test that fault handler displays crashes that happen even after
22
23
pytest is exiting (for example, when the interpreter is shutting down)."""
23
- testdir .makepyfile (
24
+ pytester .makepyfile (
24
25
"""
25
26
import faulthandler
26
27
import atexit
27
28
def test_ok():
28
29
atexit.register(faulthandler._sigabrt)
29
30
"""
30
31
)
31
- result = testdir .runpytest_subprocess ()
32
+ result = pytester .runpytest_subprocess ()
32
33
result .stderr .fnmatch_lines (["*Fatal Python error*" ])
33
34
assert result .ret != 0
34
35
35
36
36
- def test_disabled (testdir ) :
37
+ def test_disabled (pytester : Pytester ) -> None :
37
38
"""Test option to disable fault handler in the command line."""
38
- testdir .makepyfile (
39
+ pytester .makepyfile (
39
40
"""
40
41
import faulthandler
41
42
def test_disabled():
42
43
assert not faulthandler.is_enabled()
43
44
"""
44
45
)
45
- result = testdir .runpytest_subprocess ("-p" , "no:faulthandler" )
46
+ result = pytester .runpytest_subprocess ("-p" , "no:faulthandler" )
46
47
result .stdout .fnmatch_lines (["*1 passed*" ])
47
48
assert result .ret == 0
48
49
@@ -56,27 +57,27 @@ def test_disabled():
56
57
False ,
57
58
],
58
59
)
59
- def test_timeout (testdir , enabled : bool ) -> None :
60
+ def test_timeout (pytester : Pytester , enabled : bool ) -> None :
60
61
"""Test option to dump tracebacks after a certain timeout.
61
62
62
63
If faulthandler is disabled, no traceback will be dumped.
63
64
"""
64
- testdir .makepyfile (
65
+ pytester .makepyfile (
65
66
"""
66
67
import os, time
67
68
def test_timeout():
68
69
time.sleep(1 if "CI" in os.environ else 0.1)
69
70
"""
70
71
)
71
- testdir .makeini (
72
+ pytester .makeini (
72
73
"""
73
74
[pytest]
74
75
faulthandler_timeout = 0.01
75
76
"""
76
77
)
77
78
args = ["-p" , "no:faulthandler" ] if not enabled else []
78
79
79
- result = testdir .runpytest_subprocess (* args )
80
+ result = pytester .runpytest_subprocess (* args )
80
81
tb_output = "most recent call first"
81
82
if enabled :
82
83
result .stderr .fnmatch_lines (["*%s*" % tb_output ])
@@ -87,7 +88,7 @@ def test_timeout():
87
88
88
89
89
90
@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 :
91
92
"""Make sure that we are cancelling any scheduled traceback dumping due
92
93
to timeout before entering pdb (pytest-dev/pytest-faulthandler#12) or any
93
94
other interactive exception (pytest-dev/pytest-faulthandler#14)."""
@@ -108,21 +109,21 @@ def test_cancel_timeout_on_hook(monkeypatch, hook_name):
108
109
109
110
110
111
@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 :
112
113
"""Test for faulthandler being initialized earlier than pytest (#6575)."""
113
- testdir .makepyfile (
114
+ pytester .makepyfile (
114
115
"""
115
116
def test():
116
117
import faulthandler
117
118
assert faulthandler.is_enabled()
118
119
"""
119
120
)
120
- result = testdir .run (
121
+ result = pytester .run (
121
122
sys .executable ,
122
123
"-X" ,
123
124
"faulthandler" ,
124
125
"-mpytest" ,
125
- testdir . tmpdir ,
126
+ pytester . path ,
126
127
"-o" ,
127
128
f"faulthandler_timeout={ faulthandler_timeout } " ,
128
129
)
0 commit comments