{"id":4212,"library":"pytest-datadir","title":"pytest-datadir","description":"pytest-datadir is a pytest plugin designed for easily managing test data directories and files within your test suite. It provides fixtures that automatically locate and copy test data, ensuring tests operate on isolated, temporary copies. The library is actively maintained, with version 1.8.0 being the latest, and receives frequent minor updates with occasional major releases.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"https://github.com/gabrielcnr/pytest-datadir","tags":["pytest-plugin","testing","fixtures","data-files","test-data"],"install":[{"cmd":"pip install pytest-datadir","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework; pytest-datadir is a plugin for pytest.","package":"pytest","optional":false},{"reason":"Requires Python 3.8 or newer.","package":"python","optional":false}],"imports":[{"note":"pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.","symbol":"datadir","correct":"def test_something(datadir):"},{"note":"pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.","symbol":"shared_datadir","correct":"def test_something(shared_datadir):"},{"note":"Introduced in v1.7.0. pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.","symbol":"lazy_datadir","correct":"def test_something(lazy_datadir):"},{"note":"Introduced in v1.8.0. pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.","symbol":"lazy_shared_datadir","correct":"def test_something(lazy_shared_datadir):"}],"quickstart":{"code":"# File: data/hello.txt\nHello World!\n\n# File: test_hello/spam.txt\neggs\n\n# File: test_hello.py\nimport pytest\n\ndef test_read_global(shared_datadir):\n    # Accesses data from the global 'data' directory\n    contents = (shared_datadir / \"hello.txt\").read_text()\n    assert contents == \"Hello World!\\n\"\n\ndef test_read_module(datadir):\n    # Accesses data from the module-specific 'test_hello' directory\n    contents = (datadir / \"spam.txt\").read_text()\n    assert contents == \"eggs\\n\"\n","lang":"python","description":"To use `pytest-datadir`, organize your test data in a `data` directory (for global data) or subdirectories named after your test modules (e.g., `test_module/`) within your test folder. The `datadir` fixture provides access to module-specific data, while `shared_datadir` provides access to global data. Both return `pathlib.Path` objects pointing to temporary copies of your data."},"warnings":[{"fix":"Upgrade to Python 3.8 or a newer supported version.","message":"Python 2.7, 3.4, 3.5, and 3.7 are no longer supported. Version 1.4.0 dropped support for Python 2.7, 3.4, and 3.5. Version 1.5.0 dropped support for Python 3.7. The current minimum Python version required is 3.8.","severity":"breaking","affected_versions":">=1.4.0, >=1.5.0"},{"fix":"Upgrade your `pytest` installation to version 7.0 or higher: `pip install --upgrade pytest`.","message":"pytest version 7.0 or newer is now required. Older versions of pytest are not supported by recent releases of pytest-datadir.","severity":"breaking","affected_versions":">=1.6.1"},{"fix":"For versions 1.7.0 and later, consider using `lazy_datadir` or `lazy_shared_datadir` fixtures. These fixtures only copy files or directories when they are explicitly accessed via `joinpath` or the `/` operator, reducing initial setup time and resource usage.","message":"The `datadir` and `shared_datadir` fixtures eagerly copy all associated test data files to a temporary directory at the start of the test. For large data sets or numerous small files, this can introduce performance overhead.","severity":"gotcha","affected_versions":"<1.7.0 (primary concern), all versions (performance consideration)"},{"fix":"Review tests that use `original_datadir` and adjust them if they implicitly depended on a function-level scope. If you need function-level isolation for original data, you might need to manually copy from `original_datadir` within your test function or use `datadir` for the temporary copy behavior.","message":"The `original_datadir` fixture changed its scope from function-scoped to module-scoped in version 1.6.0. This might affect tests that relied on its previous behavior.","severity":"gotcha","affected_versions":">=1.6.0"},{"fix":"Prefer `tmp_path` over `tmpdir` in your own fixtures and test code. `pytest-datadir` fixtures (`datadir`, `shared_datadir`, etc.) already return `pathlib.Path` objects, aligning with the modern `pytest` approach.","message":"The underlying pytest `tmpdir` fixture, which returns a `py.path.local` object, has been deprecated by pytest itself in favor of `tmp_path`, which returns a `pathlib.Path` object. While `pytest-datadir` internally transitioned to `tmp_path` in v1.4.1, users migrating older tests or using `tmpdir` directly should be aware.","severity":"deprecated","affected_versions":"All versions of `pytest-datadir` with older `pytest` versions, specifically `pytest` core versions >=7.0"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}