1111
1212**Documenting Tests**
1313To 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.
2916
3017 Expects
3118 -------
5340tests and between different test runs. This is primarly used with `cases` so that tests
5441requiring the same kind of expensive case and used cached values.
5542
56- Use `pytest --cache-clear ` to clear the cahce
43+ Use `pytest --cached ` to use this feature.
5744
5845See `test/test_automl/cases.py` for example of how the fixtures from
5946`test/fixtures/caching.py` can be used to cache objects between tests.
@@ -87,6 +74,7 @@ def test_something_does_x(arg1, make_something):
8774from typing import Any , Iterator , List , Optional
8875
8976import re
77+ import shutil
9078import signal
9179from pathlib import Path
9280
@@ -99,7 +87,7 @@ def test_something_does_x(arg1, make_something):
9987
10088
10189HERE = Path (__file__ )
102- AUTOSKLEARN_CACHE_NAME = "autosklearn"
90+ AUTOSKLEARN_CACHE_NAME = "autosklearn-cache "
10391
10492
10593def walk (path : Path , include : Optional [str ] = None ) -> Iterator [Path ]:
@@ -162,6 +150,18 @@ def pytest_sessionstart(session: Session) -> None:
162150 session : Session
163151 The pytest session object
164152 """
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+
165165 return
166166
167167
@@ -202,7 +202,6 @@ def pytest_collection_modifyitems(
202202def pytest_configure (config : Config ) -> None :
203203 """Used to register marks"""
204204 config .addinivalue_line ("markers" , "todo: Mark test as todo" )
205- config .addinivalue_line ("markers" , "slow: Mark test as slow" )
206205
207206
208207pytest_plugins = fixture_modules ()
@@ -225,3 +224,9 @@ def pytest_addoption(parser: Parser) -> None:
225224 default = False ,
226225 help = "Disable tests marked as slow" ,
227226 )
227+ parser .addoption (
228+ "--cached" ,
229+ action = "store_true" ,
230+ default = False ,
231+ help = "Cache everything between invocations of pytest" ,
232+ )
0 commit comments