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