Registry / testing / pytest-resource-path

pytest-resource-path

JSON →
library1.5.0pypypi✓ verified 86d ago

Provides a pytest fixture `resource_path` that gives a pathlib.Path to a temporary directory with uniform access to test resources, copying test-resource directories from the test file's directory. Version 1.5.0 supports Python >=3.7.

pip install pytest-resource-path
INSTALL
IMPORT
SIG · PYTEST-RESOURCE-PA
P
pytest-resource-path
testingpythonv1.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

resource_path
from pytest_resource_path import resource_path
from pytest_resources import resource_path
Common mistake: using singular 'resource' or incorrect package name

Basic usage: the `resource_path` fixture provides a Path to a temporary directory containing resources that were co-located with the test file in a directory named `test-resource/`.

import os import pytest from pathlib import Path def test_example(resource_path: Path): # resource_path points to a temporary directory with test resources assert resource_path.is_dir() resource_file = resource_path / 'data.txt' if resource_file.exists(): content = resource_file.read_text() assert 'expected' in content
Debug
Known issues
gotchaThe fixture copies resource files from a directory named `test-resource/` relative to the test file. If the directory is named differently (e.g., `resources/`), the fixture will not copy anything. Ensure your resource directory is named exactly `test-resource`.
fix
Rename your resource directory to `test-resource/` or configure via `--resource-path-dir` CLI option.
affects: all
gotchaThe `resource_path` variable is a `pathlib.Path` to a temporary directory that is cleaned up after each test. Do not store paths outside the test function scope.
fix
Use `resource_path` directly inside the test; avoid saving it to class-level variables.
affects: all
deprecatedIn older versions (<1.0), the fixture was named `resources_path` and returned a string. Use `resource_path` (singular) returning a `pathlib.Path` in current versions.
fix
Rename fixture to `resource_path` and use `pathlib.Path` methods instead of string concatenation.
affects: <1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_resources'
Incorrect import path; the correct package is `pytest_resource_path`.
fix
Install with `pip install pytest-resource-path` and import as `from pytest_resource_path import resource_path`.
Fixture 'resource_path' not found
The package is not installed or not registered as a pytest plugin. Pytest discovers it via entry points if installed correctly.
fix
Ensure `pytest-resource-path` is installed in the current environment: `pip list | grep pytest-resource`.
AttributeError: 'PosixPath' object has no attribute 'read_text'
Using older Python versions (<3.7) that lack `pathlib.Path.read_text()`. But the package requires Python >=3.7, so this should not happen if your environment meets the requirement. Likely a different object.
fix
Check that `resource_path` is a `pathlib.Path`. If not, ensure correct version of the package.
FileNotFoundError: [Errno 2] No such file or directory: '.../test-resource/data.txt'
Resource file not present in the `test-resource` directory next to the test file.
fix
Create a directory named `test-resource` in the same folder as your test file and place the resource file inside.
Upgrade
Version history
1.5.0latest on PyPI · released May 17, 2026
Audit
Dependencies
pytestrequiredRequired for running tests and fixture registration
Agent activity
4 hits · last 30 days
node
4
Resources

No resource links recorded.

pytest-resource-path — pip install pytest-resource-path · libregistry