pytest.cleandir#
- maite.testing.pytest.cleandir()[source]#
A pytest fixture that runs a test in a temporary directory as the current working directory.
This is helpful for running tests that require file I/O that could pollute local directories. File cleanup is handled automatically.
- Yields:
- tmpdirnamestr
Temporary directory name that will be removed at fixture teardown
Examples
This assumes that
cleandir
has been imported by the test suite’sconftest.py
file.>>> import pytest >>> @pytest.mark.usefixtures("cleandir") ... def test_writes_some_file(): ... from pathlib import Path ... Path("dummy.txt").touch() # file will be written to a tmp dir