August 2018
Beginner
160 pages
4h 8m
English
The tmpdir fixture is very handy, but it is only function-scoped: this has the downside that it can only be used by other function-scoped fixtures.
The tmpdir_factory fixture is a session-scoped fixture that allows creating empty and unique directories at any scope. This can be useful when we need to store data on to a disk in fixtures of other scopes, for example a session-scoped cache or a database file.
To show it in action, the images_dir fixture shown next uses tmpdir_factory to create a unique directory for the entire test session containing a series of sample image files:
@pytest.fixture(scope='session')def images_dir(tmpdir_factory): directory = tmpdir_factory.mktemp('images') download_images('https://example.com/samples.zip', ...Read now
Unlock full access