pytest-datafiles is a pytest plugin that simplifies testing by providing a convenient way to make files and directories available to your tests within a temporary directory (leveraging pytest's `tmp_path` fixture). It uses a decorator to specify which files or directories from your source tree should be copied. The current version is 3.0.1, with releases typically happening for bug fixes, new features, or breaking changes in underlying dependencies like pytest or Python versions.
pip install pytest-datafilesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `@pytest.mark.datafiles` decorator to specify files to be copied into a temporary directory for your test. The `datafiles` fixture, a `pathlib.Path` object, is then used within the test function to access these files. The example sets up temporary dummy data files for demonstration purposes.
Update your tests to use `pathlib.Path` methods (e.g., `/` for joining paths, `.read_text()`, `.exists()`) instead of `py.path` methods (e.g., `.join()`, `.read()`). For example, `datafiles.join('my_file.txt')` becomes `datafiles / 'my_file.txt'`.Upgrade your Python environment to Python 3.7 or newer. Python 3.8+ is recommended.
Ensure your pytest installation is `pytest>=6.2.0`. If you experience issues like 'fixture 'tmp_path' not found', your pytest version might be too old.
Adjust your tests to account for symlinks being preserved as links rather than being dereferenced during the copy operation. If you need the target content, you'll need to resolve the symlink within your test (e.g., `symlink_path.resolve()`).
Refactor your path manipulation to use `pathlib.Path` methods. For path joining, replace `.join('filename')` with `/ 'filename'`. Example: `datafiles / 'my_file.txt'`.Ensure `pytest-datafiles` is installed (`pip install pytest-datafiles`). If the issue persists, check your `pytest.ini` or `pyproject.toml` for `markers` configuration that might override or incorrectly list markers. This warning usually doesn't stop tests from running, but indicates a potential setup issue.
Upgrade your pytest installation to a compatible version: `pip install --upgrade pytest>=6.2.0`.