Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Universe copy fixture #1488
Creating large scoped fixtures for Universes (ie create one Universe for multiple tests) will save a lot of time in some cases (assuming that copying the Universe is quicker than parsing the files). Universe copying is currently an open issue (#1249) but I think it might be possible to get this done soon if there's a good reason, ie this issue.
So in the original discussion, I had to use a kind of ugly two stage fixture to make this work, ie
@pytest.fixture(scope='module') def first_fixture(): return value @pytest.fixture(scope='function') def second_fixture(first_fixture): myval = copy.copy(first_fixture) return my_modification(myval)
It would be preferable to create some sort of module scoped fixture, which returned a deepcopy each time it was used, maybe by hiding the real fixture as a private version...
# hidden away in some file full of fixtures... @pytest.fixture(scope='module') # or whatever the biggest scope is... def _hidden_PSF_DCD(): return mda.Universe(PSF, DCD) # also hidden away, does the copying @pytest.fixture(scope='function') def PSF_DCD(_hidden_PSF_DCD): return _hidden_PSF_DCD.copy() # within a specific set of tests @pytest.fixture(scope='function') def my_PSF_fixture(PSF_DCD): # at this point I'm oblivious that I'm using a version of Universe that came from a copy return PSF_DCD.atoms[:10]