11
11
12
12
**Documenting Tests**
13
13
To ease in understanding of tests, what is being tested and what's expected of the test,
14
- each test should be documented with what it's parameters/fixtures are as well as what
15
- the test expects to happen, regardless of the tests implemntation.
16
-
17
- Parameters
18
- ----------
19
- param1: Type
20
- ...
21
-
22
- param2: Type
23
- ...
24
-
25
- Fixtures
26
- --------
27
- make_something: Callable[..., Something]
28
- Factory to make Something
14
+ each test should doc expected bhaviour, not describe the steps of the test.
15
+ Commenst relating to how a test does things can be left in the tests and not the doc.
29
16
30
17
Expects
31
18
-------
53
40
tests and between different test runs. This is primarly used with `cases` so that tests
54
41
requiring the same kind of expensive case and used cached values.
55
42
56
- Use `pytest --cache-clear ` to clear the cahce
43
+ Use `pytest --cached ` to use this feature.
57
44
58
45
See `test/test_automl/cases.py` for example of how the fixtures from
59
46
`test/fixtures/caching.py` can be used to cache objects between tests.
@@ -87,6 +74,7 @@ def test_something_does_x(arg1, make_something):
87
74
from typing import Any , Iterator , List , Optional
88
75
89
76
import re
77
+ import shutil
90
78
import signal
91
79
from pathlib import Path
92
80
@@ -99,7 +87,7 @@ def test_something_does_x(arg1, make_something):
99
87
100
88
101
89
HERE = Path (__file__ )
102
- AUTOSKLEARN_CACHE_NAME = "autosklearn"
90
+ AUTOSKLEARN_CACHE_NAME = "autosklearn-cache "
103
91
104
92
105
93
def walk (path : Path , include : Optional [str ] = None ) -> Iterator [Path ]:
@@ -162,6 +150,18 @@ def pytest_sessionstart(session: Session) -> None:
162
150
session : Session
163
151
The pytest session object
164
152
"""
153
+ config = session .config
154
+ cache = config .cache
155
+
156
+ if cache is None :
157
+ return
158
+
159
+ # We specifically only remove the cached items dir, not any information
160
+ # about previous tests which also exist in `.pytest_cache`
161
+ if not config .getoption ("--cached" ):
162
+ dir = cache .mkdir (AUTOSKLEARN_CACHE_NAME )
163
+ shutil .rmtree (dir )
164
+
165
165
return
166
166
167
167
@@ -202,7 +202,6 @@ def pytest_collection_modifyitems(
202
202
def pytest_configure (config : Config ) -> None :
203
203
"""Used to register marks"""
204
204
config .addinivalue_line ("markers" , "todo: Mark test as todo" )
205
- config .addinivalue_line ("markers" , "slow: Mark test as slow" )
206
205
207
206
208
207
pytest_plugins = fixture_modules ()
@@ -225,3 +224,9 @@ def pytest_addoption(parser: Parser) -> None:
225
224
default = False ,
226
225
help = "Disable tests marked as slow" ,
227
226
)
227
+ parser .addoption (
228
+ "--cached" ,
229
+ action = "store_true" ,
230
+ default = False ,
231
+ help = "Cache everything between invocations of pytest" ,
232
+ )
0 commit comments