11import os
22from io import StringIO
3+ from typing import List
34
45import _pytest ._code
56import pytest
7+ from _pytest .pytester import Testdir
68from _pytest .resultlog import pytest_configure
79from _pytest .resultlog import pytest_unconfigure
810from _pytest .resultlog import ResultLog
911from _pytest .resultlog import resultlog_key
1012
13+
1114pytestmark = pytest .mark .filterwarnings ("ignore:--result-log is deprecated" )
1215
1316
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]
1619 reslog .logfile = StringIO ()
1720 reslog .write_log_entry ("name" , "." , "" )
1821 entry = reslog .logfile .getvalue ()
@@ -54,14 +57,14 @@ class TestWithFunctionIntegration:
5457 # XXX (hpk) i think that the resultlog plugin should
5558 # provide a Parser object so that one can remain
5659 # ignorant regarding formatting details.
57- def getresultlog (self , testdir , arg ) :
60+ def getresultlog (self , testdir : Testdir , arg : str ) -> List [ str ] :
5861 resultlog = testdir .tmpdir .join ("resultlog" )
5962 testdir .plugins .append ("resultlog" )
6063 args = ["--resultlog=%s" % resultlog ] + [arg ]
6164 testdir .runpytest (* args )
6265 return [x for x in resultlog .readlines (cr = 0 ) if x ]
6366
64- def test_collection_report (self , testdir ) :
67+ def test_collection_report (self , testdir : Testdir ) -> None :
6568 ok = testdir .makepyfile (test_collection_ok = "" )
6669 fail = testdir .makepyfile (test_collection_fail = "XXX" )
6770 lines = self .getresultlog (testdir , ok )
@@ -75,7 +78,7 @@ def test_collection_report(self, testdir):
7578 assert x .startswith (" " )
7679 assert "XXX" in "" .join (lines [1 :])
7780
78- def test_log_test_outcomes (self , testdir ) :
81+ def test_log_test_outcomes (self , testdir : Testdir ) -> None :
7982 mod = testdir .makepyfile (
8083 test_mod = """
8184 import pytest
@@ -111,16 +114,17 @@ def test_xpass(): pass
111114 assert len (lines ) == 15
112115
113116 @pytest .mark .parametrize ("style" , ("native" , "long" , "short" ))
114- def test_internal_exception (self , style ):
117+ def test_internal_exception (self , style ) -> None :
115118 # they are produced for example by a teardown failing
116119 # at the end of the run or a failing hook invocation
117120 try :
118121 raise ValueError
119122 except ValueError :
120123 excinfo = _pytest ._code .ExceptionInfo .from_current ()
121- reslog = ResultLog (None , StringIO ())
124+ file = StringIO ()
125+ reslog = ResultLog (None , file ) # type: ignore[arg-type]
122126 reslog .pytest_internalerror (excinfo .getrepr (style = style ))
123- entry = reslog . logfile .getvalue ()
127+ entry = file .getvalue ()
124128 entry_lines = entry .splitlines ()
125129
126130 assert entry_lines [0 ].startswith ("! " )
@@ -130,7 +134,7 @@ def test_internal_exception(self, style):
130134 assert "ValueError" in entry
131135
132136
133- def test_generic (testdir , LineMatcher ):
137+ def test_generic (testdir : Testdir , LineMatcher ) -> None :
134138 testdir .plugins .append ("resultlog" )
135139 testdir .makepyfile (
136140 """
@@ -162,7 +166,7 @@ def test_xfail_norun():
162166 )
163167
164168
165- def test_makedir_for_resultlog (testdir , LineMatcher ):
169+ def test_makedir_for_resultlog (testdir : Testdir , LineMatcher ) -> None :
166170 """--resultlog should automatically create directories for the log file"""
167171 testdir .plugins .append ("resultlog" )
168172 testdir .makepyfile (
@@ -177,7 +181,7 @@ def test_pass():
177181 LineMatcher (lines ).fnmatch_lines ([". *:test_pass" ])
178182
179183
180- def test_no_resultlog_on_workers (testdir ) :
184+ def test_no_resultlog_on_workers (testdir : Testdir ) -> None :
181185 config = testdir .parseconfig ("-p" , "resultlog" , "--resultlog=resultlog" )
182186
183187 assert resultlog_key not in config ._store
@@ -186,14 +190,14 @@ def test_no_resultlog_on_workers(testdir):
186190 pytest_unconfigure (config )
187191 assert resultlog_key not in config ._store
188192
189- config .workerinput = {}
193+ config .workerinput = {} # type: ignore[attr-defined]
190194 pytest_configure (config )
191195 assert resultlog_key not in config ._store
192196 pytest_unconfigure (config )
193197 assert resultlog_key not in config ._store
194198
195199
196- def test_unknown_teststatus (testdir ) :
200+ def test_unknown_teststatus (testdir : Testdir ) -> None :
197201 """Ensure resultlog correctly handles unknown status from pytest_report_teststatus
198202
199203 Inspired on pytest-rerunfailures.
@@ -229,7 +233,7 @@ def pytest_runtest_makereport():
229233 assert lines [0 ] == "r test_unknown_teststatus.py::test"
230234
231235
232- def test_failure_issue380 (testdir ) :
236+ def test_failure_issue380 (testdir : Testdir ) -> None :
233237 testdir .makeconftest (
234238 """
235239 import pytest
0 commit comments