-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "global_datadir" fixture too? #28
Comments
This is very nice. I've found myself wanting this in multiple projects |
You can simplify a bit by using the request context.
note that your package_path only looks up one directory above the current directory so if you either have a test that is already in the root dir or a test that is nested several levels down, this won't work. I'm looking through the request object for something that could get the data dir in the root tests directory, but it looks like we might need to walk the dirs. hmm... surely pytest can tell us where the root conftest.py is?
|
I hope there's a way to make this more generic so it can be included in this plugin, but here's what I just put together in conftest.py in the root tests directory of my project. import os
import pathlib
import pytest
import shutil
@pytest.fixture(scope="session")
def original_global_datadir():
return pathlib.Path(os.path.realpath(__file__)).parent / "data"
def prep_global_datadir(tmp_path_factory, original_global_datadir):
temp_dir = tmp_path_factory.mktemp("data") / "datadir"
shutil.copytree(original_global_datadir, temp_dir)
return temp_dir
@pytest.fixture(scope="session")
def session_global_datadir(tmp_path_factory, original_global_datadir):
return prep_global_datadir(tmp_path_factory, original_global_datadir)
@pytest.fixture(scope="module")
def module_global_datadir(tmp_path_factory, original_global_datadir):
return prep_global_datadir(tmp_path_factory, original_global_datadir)
@pytest.fixture(scope="function")
def global_datadir(tmp_path_factory, original_global_datadir):
return prep_global_datadir(tmp_path_factory, original_global_datadir) |
I usually put such "global" fixtures in |
Any plans on integrating this functionality? |
When the testsuite has nested directories,
shared_datadir
tries to find adata
directory inside each level. This is useful but in some cases you might also want to have a truly "global" datadir.I think it would make sense if a
global_datadir
fixture was added that would always reference thedata
directory at the top level of the tests directory. If there is a single nest level, thenshared_datadir
andglobal_datadir
should point to the same dir.The implementation could be something like this (not thoroughly tested, e.g. I haven't tried it for namespace packages etc):
Should I make a PR?
The text was updated successfully, but these errors were encountered: