- tmpdir
Pytest fixture - tmpdir
- Probably the simples fixture that PyTest can provide is the tmpdir.
- Pytest will prepare a temporary directory and call the test function passing the path to the tmpdir.
- PyTest will also clean up the temporary folder, though it will keep the 3 most recent ones. (this is configurable)
examples/pytest/test_tmpdir.py
import os def test_something(tmpdir): print(tmpdir) # /private/var/folders/ry/z60xxmw0000gn/T/pytest-of-gabor/pytest-14/test_read0 d = tmpdir.mkdir("subdir") fh = d.join("config.ini") fh.write("Some text") filename = os.path.join( fh.dirname, fh.basename ) temp_dir = str(tmpdir) # ...