tmp_files
- pytest_tmp_files.tmp_files(request, tmp_path)[source]
An extension of
tmp_paththat can create a temporary file hierarchy when indirectly parametrized.- Returns:
The object provided to the test function by this fixture will be a
pathlib.Pathreferring to the temporary directory that was created. This path will also have a manifest attribute containing the dictionary that specified which files to create.
In order to use this fixture, simply specify tmp_files as an argument to any of your test functions. There’s no need to import anything; this plugin installs itself so that pytest will automatically be able to find this fixture.
You must use indirect parametrization to specify which files to create. Any dictionary matching the format described here can be used as a parameter. Here’s an example of what this looks like:
import pytest @pytest.mark.parametrize( 'tmp_files, ...', [ ({'path/to/file': 'file contents'}, ...), ... ], indirect=['tmp_files'], ) def test_my_function(tmp_files, ...): ...
Note the indirect argument. This specifies that the tmp_files parameters should be made available to the
tmp_filesfixture. Also note that each set of parameters will get its own file hierarchy. This is good for making each test independent from all the others.If you don’t want to use parametrization (e.g. if you only have one scenario you want to test), you probably don’t want to use this fixture. Instead, use the
tmp_pathfixture and callmake_fileswithin the test function to create your file hierarchy.