pytest-datafiles
pytest-datafiles copied to clipboard
ScopeMismatch error
I am running into an issue where I get a "ScopeMismatch" error if I try to use datafiles to create another fixture with a different scope than "function".
I want the scope to be "module" based because I would like to keep the database open for all tests since loading the database is time consuming.
Here is a simplified example of what I am trying to do:
@pytest.fixture(scope="module")
@pytest.mark.datafiles(TEST_DATA_DIR / "image.png")
def image_db(datafiles):
"""Loads image.png into database and returns database entry"""
with database():
database.add(datafiles / "image.png")
for db_entry in database.query_images():
yield db_entry
break
test setup failed
ScopeMismatch: You tried to access the 'function' scoped fixture 'datafiles' with a 'module' scoped request object, involved factories
Any help is a appreciated.