Add output_dir fixture
Adds the output_dir fixture and make the logger fixture use it
Extract from the README
Fixtures
output_dir
A function-scoped fixture that yields a Path to a directory unique to the running test, created under --output-dir (default: ./output).
The path is derived from the test's nodeid, with test_ stripped from file and function names and Test stripped from class names:
| nodeid | output path |
|---|---|
test_foo.py::test_bar |
output/foo/bar |
test_foo.py::test_bar[x-y] |
output/foo/bar/x-y |
test_foo.py::TestSuite::test_bar |
output/foo/Suite/bar |
sub/test_foo.py::test_bar |
output/sub/foo/bar |
The directory is created before the test runs. After the test, it is removed only if empty — any files written during the test are preserved.
Options:
--output-dir— base output directory (default:./output)--output-dir-clean-on-start— wipe the entire output directory at session start
Example:
def test_something(output_dir):
result = run_thing()
(output_dir / "result.json").write_text(result)logger
A function-scoped fixture that yields a Logger bound to the running test, writing to output_dir/test.log.
The logger is named after the test's nodeid (e.g. tests/test_foo.py::test_bar). The log file uses the format %(levelname)s: %(message)s.
Example:
import logging
def test_something(logger):
logger.info("starting test")
...
logger.info("done")