tmp_files
- pytest_tmp_files.tmp_files(request, tmp_path)[source]
An extension of
tmp_path
that can create a temporary file hierarchy when indirectly parametrized.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 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_files
fixture. 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_path
fixture and callmake_files
within the test function to create your file hierarchy.