1
1
import os
2
2
from io import StringIO
3
+ from typing import List
3
4
4
5
import _pytest ._code
5
6
import pytest
7
+ from _pytest .pytester import Testdir
6
8
from _pytest .resultlog import pytest_configure
7
9
from _pytest .resultlog import pytest_unconfigure
8
10
from _pytest .resultlog import ResultLog
9
11
from _pytest .resultlog import resultlog_key
10
12
13
+
11
14
pytestmark = pytest .mark .filterwarnings ("ignore:--result-log is deprecated" )
12
15
13
16
14
- def test_write_log_entry ():
15
- reslog = ResultLog (None , None )
17
+ def test_write_log_entry () -> None :
18
+ reslog = ResultLog (None , None ) # type: ignore[arg-type]
16
19
reslog .logfile = StringIO ()
17
20
reslog .write_log_entry ("name" , "." , "" )
18
21
entry = reslog .logfile .getvalue ()
@@ -54,14 +57,14 @@ class TestWithFunctionIntegration:
54
57
# XXX (hpk) i think that the resultlog plugin should
55
58
# provide a Parser object so that one can remain
56
59
# ignorant regarding formatting details.
57
- def getresultlog (self , testdir , arg ) :
60
+ def getresultlog (self , testdir : Testdir , arg : str ) -> List [ str ] :
58
61
resultlog = testdir .tmpdir .join ("resultlog" )
59
62
testdir .plugins .append ("resultlog" )
60
63
args = ["--resultlog=%s" % resultlog ] + [arg ]
61
64
testdir .runpytest (* args )
62
65
return [x for x in resultlog .readlines (cr = 0 ) if x ]
63
66
64
- def test_collection_report (self , testdir ) :
67
+ def test_collection_report (self , testdir : Testdir ) -> None :
65
68
ok = testdir .makepyfile (test_collection_ok = "" )
66
69
fail = testdir .makepyfile (test_collection_fail = "XXX" )
67
70
lines = self .getresultlog (testdir , ok )
@@ -75,7 +78,7 @@ def test_collection_report(self, testdir):
75
78
assert x .startswith (" " )
76
79
assert "XXX" in "" .join (lines [1 :])
77
80
78
- def test_log_test_outcomes (self , testdir ) :
81
+ def test_log_test_outcomes (self , testdir : Testdir ) -> None :
79
82
mod = testdir .makepyfile (
80
83
test_mod = """
81
84
import pytest
@@ -111,16 +114,17 @@ def test_xpass(): pass
111
114
assert len (lines ) == 15
112
115
113
116
@pytest .mark .parametrize ("style" , ("native" , "long" , "short" ))
114
- def test_internal_exception (self , style ):
117
+ def test_internal_exception (self , style ) -> None :
115
118
# they are produced for example by a teardown failing
116
119
# at the end of the run or a failing hook invocation
117
120
try :
118
121
raise ValueError
119
122
except ValueError :
120
123
excinfo = _pytest ._code .ExceptionInfo .from_current ()
121
- reslog = ResultLog (None , StringIO ())
124
+ file = StringIO ()
125
+ reslog = ResultLog (None , file ) # type: ignore[arg-type]
122
126
reslog .pytest_internalerror (excinfo .getrepr (style = style ))
123
- entry = reslog . logfile .getvalue ()
127
+ entry = file .getvalue ()
124
128
entry_lines = entry .splitlines ()
125
129
126
130
assert entry_lines [0 ].startswith ("! " )
@@ -130,7 +134,7 @@ def test_internal_exception(self, style):
130
134
assert "ValueError" in entry
131
135
132
136
133
- def test_generic (testdir , LineMatcher ):
137
+ def test_generic (testdir : Testdir , LineMatcher ) -> None :
134
138
testdir .plugins .append ("resultlog" )
135
139
testdir .makepyfile (
136
140
"""
@@ -162,7 +166,7 @@ def test_xfail_norun():
162
166
)
163
167
164
168
165
- def test_makedir_for_resultlog (testdir , LineMatcher ):
169
+ def test_makedir_for_resultlog (testdir : Testdir , LineMatcher ) -> None :
166
170
"""--resultlog should automatically create directories for the log file"""
167
171
testdir .plugins .append ("resultlog" )
168
172
testdir .makepyfile (
@@ -177,7 +181,7 @@ def test_pass():
177
181
LineMatcher (lines ).fnmatch_lines ([". *:test_pass" ])
178
182
179
183
180
- def test_no_resultlog_on_workers (testdir ) :
184
+ def test_no_resultlog_on_workers (testdir : Testdir ) -> None :
181
185
config = testdir .parseconfig ("-p" , "resultlog" , "--resultlog=resultlog" )
182
186
183
187
assert resultlog_key not in config ._store
@@ -186,14 +190,14 @@ def test_no_resultlog_on_workers(testdir):
186
190
pytest_unconfigure (config )
187
191
assert resultlog_key not in config ._store
188
192
189
- config .workerinput = {}
193
+ config .workerinput = {} # type: ignore[attr-defined]
190
194
pytest_configure (config )
191
195
assert resultlog_key not in config ._store
192
196
pytest_unconfigure (config )
193
197
assert resultlog_key not in config ._store
194
198
195
199
196
- def test_unknown_teststatus (testdir ) :
200
+ def test_unknown_teststatus (testdir : Testdir ) -> None :
197
201
"""Ensure resultlog correctly handles unknown status from pytest_report_teststatus
198
202
199
203
Inspired on pytest-rerunfailures.
@@ -229,7 +233,7 @@ def pytest_runtest_makereport():
229
233
assert lines [0 ] == "r test_unknown_teststatus.py::test"
230
234
231
235
232
- def test_failure_issue380 (testdir ) :
236
+ def test_failure_issue380 (testdir : Testdir ) -> None :
233
237
testdir .makeconftest (
234
238
"""
235
239
import pytest
0 commit comments