1313import sys
1414
1515from typing import Iterator , Tuple
16+ from typing import Iterable , Optional
1617
1718import pytest
1819
@@ -24,26 +25,26 @@ class PytestBase:
2425 """A base class to connect to pytest in a test class hierarchy."""
2526
2627 @pytest .fixture (autouse = True )
27- def connect_to_pytest (self , request , monkeypatch ):
28+ def connect_to_pytest (self , request , monkeypatch ) -> None :
2829 """Captures pytest facilities for use by other test helpers."""
2930 # pylint: disable=attribute-defined-outside-init
3031 self ._pytest_request = request
3132 self ._monkeypatch = monkeypatch
3233 self .setUp ()
3334
34- def setUp (self ):
35+ def setUp (self ) -> None :
3536 """Per-test initialization. Override this as you wish."""
3637 pass
3738
38- def addCleanup (self , fn , * args ):
39+ def addCleanup (self , fn , * args ) -> None :
3940 """Like unittest's addCleanup: code to call when the test is done."""
4041 self ._pytest_request .addfinalizer (lambda : fn (* args ))
4142
42- def set_environ (self , name , value ):
43+ def set_environ (self , name , value ) -> None :
4344 """Set an environment variable `name` to be `value`."""
4445 self ._monkeypatch .setenv (name , value )
4546
46- def del_environ (self , name ):
47+ def del_environ (self , name ) -> None :
4748 """Delete an environment variable, unless we set it."""
4849 self ._monkeypatch .delenv (name , raising = False )
4950
@@ -72,7 +73,13 @@ def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
7273 else :
7374 yield
7475
75- def make_file (self , filename , text = "" , bytes = b"" , newline = None ):
76+ def make_file (
77+ self ,
78+ filename : str ,
79+ text : str = "" ,
80+ bytes : bytes = b"" ,
81+ newline : Optional [str ]= None ,
82+ ) -> str :
7683 """Make a file. See `tests.helpers.make_file`"""
7784 # pylint: disable=redefined-builtin # bytes
7885 assert self .run_in_temp_dir , "Only use make_file when running in a temp dir"
@@ -83,15 +90,15 @@ class RestoreModulesMixin:
8390 """Auto-restore the imported modules at the end of each test."""
8491
8592 @pytest .fixture (autouse = True )
86- def _module_saving (self ):
93+ def _module_saving (self ) -> Iterable [ None ] :
8794 """Remove modules we imported during the test."""
8895 self ._sys_module_saver = SysModuleSaver ()
8996 try :
9097 yield
9198 finally :
9299 self ._sys_module_saver .restore ()
93100
94- def clean_local_file_imports (self ):
101+ def clean_local_file_imports (self ) -> None :
95102 """Clean up the results of calls to `import_local_file`.
96103
97104 Use this if you need to `import_local_file` the same file twice in
@@ -120,7 +127,7 @@ class StdStreamCapturingMixin:
120127
121128 """
122129 @pytest .fixture (autouse = True )
123- def _capcapsys (self , capsys ) :
130+ def _capcapsys (self , capsys : pytest . CaptureFixture [ str ]) -> None :
124131 """Grab the fixture so our methods can use it."""
125132 self .capsys = capsys
126133
0 commit comments