pytest-xfiles
raw JSON → 0.2.0 verified Sat May 09 auth: no python
pytest-xfiles provides fixtures that read test data from files named after the test function, module, or package (xfiles). Current version 0.2.0, with no recent updates; likely in maintenance mode.
pip install pytest-xfiles Common errors
error ModuleNotFoundError: No module named 'pytest_xfiles' ↓
cause The package is installed as 'pytest-xfiles' but Python import uses underscores.
fix
Install with 'pip install pytest-xfiles' and import with 'from pytest_xfiles import xfiles'.
error TypeError: 'module' object is not callable ↓
cause Incorrect import of entire module instead of the fixture.
fix
Use the fixture name 'xfiles' as a test function parameter, not as import.
error FileNotFoundError: [Errno 2] No such file or directory ↓
cause Xfile not found in expected location or with wrong naming convention.
fix
Check that the xfile path follows the pattern: test_<function>.xfile or test_<function>/<any>.xfile in the same directory.
Warnings
deprecated pytest-xfiles has not been updated since 2016; may not work with newer pytest versions (>5). ↓
fix Consider alternative fixtures or pin pytest version.
gotcha The xfiles fixture returns a function, not the file content directly. You must call it. ↓
fix Use xfiles() to read the content, not just reference the fixture.
gotcha Xfile naming convention expects specific file extensions and paths; deviation leads to FileNotFoundError. ↓
fix Ensure xfile follows the naming pattern: test_func.xfile or test_func/*.xfile.
Imports
- xfiles
from pytest_xfiles import xfiles
Quickstart
import pytest
def test_read_func_xfile(xfiles):
"""Test function-level xfile."""
# The fixture returns a reader function
data = xfiles()
assert data is not None