13
13
import sys
14
14
15
15
from typing import Iterator , Tuple
16
+ from typing import Iterable , Optional
16
17
17
18
import pytest
18
19
@@ -24,26 +25,26 @@ class PytestBase:
24
25
"""A base class to connect to pytest in a test class hierarchy."""
25
26
26
27
@pytest .fixture (autouse = True )
27
- def connect_to_pytest (self , request , monkeypatch ):
28
+ def connect_to_pytest (self , request , monkeypatch ) -> None :
28
29
"""Captures pytest facilities for use by other test helpers."""
29
30
# pylint: disable=attribute-defined-outside-init
30
31
self ._pytest_request = request
31
32
self ._monkeypatch = monkeypatch
32
33
self .setUp ()
33
34
34
- def setUp (self ):
35
+ def setUp (self ) -> None :
35
36
"""Per-test initialization. Override this as you wish."""
36
37
pass
37
38
38
- def addCleanup (self , fn , * args ):
39
+ def addCleanup (self , fn , * args ) -> None :
39
40
"""Like unittest's addCleanup: code to call when the test is done."""
40
41
self ._pytest_request .addfinalizer (lambda : fn (* args ))
41
42
42
- def set_environ (self , name , value ):
43
+ def set_environ (self , name , value ) -> None :
43
44
"""Set an environment variable `name` to be `value`."""
44
45
self ._monkeypatch .setenv (name , value )
45
46
46
- def del_environ (self , name ):
47
+ def del_environ (self , name ) -> None :
47
48
"""Delete an environment variable, unless we set it."""
48
49
self ._monkeypatch .delenv (name , raising = False )
49
50
@@ -72,7 +73,13 @@ def _temp_dir(self, tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
72
73
else :
73
74
yield
74
75
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 :
76
83
"""Make a file. See `tests.helpers.make_file`"""
77
84
# pylint: disable=redefined-builtin # bytes
78
85
assert self .run_in_temp_dir , "Only use make_file when running in a temp dir"
@@ -83,15 +90,15 @@ class RestoreModulesMixin:
83
90
"""Auto-restore the imported modules at the end of each test."""
84
91
85
92
@pytest .fixture (autouse = True )
86
- def _module_saving (self ):
93
+ def _module_saving (self ) -> Iterable [ None ] :
87
94
"""Remove modules we imported during the test."""
88
95
self ._sys_module_saver = SysModuleSaver ()
89
96
try :
90
97
yield
91
98
finally :
92
99
self ._sys_module_saver .restore ()
93
100
94
- def clean_local_file_imports (self ):
101
+ def clean_local_file_imports (self ) -> None :
95
102
"""Clean up the results of calls to `import_local_file`.
96
103
97
104
Use this if you need to `import_local_file` the same file twice in
@@ -120,7 +127,7 @@ class StdStreamCapturingMixin:
120
127
121
128
"""
122
129
@pytest .fixture (autouse = True )
123
- def _capcapsys (self , capsys ) :
130
+ def _capcapsys (self , capsys : pytest . CaptureFixture [ str ]) -> None :
124
131
"""Grab the fixture so our methods can use it."""
125
132
self .capsys = capsys
126
133
0 commit comments