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

Universe copy fixture #1488

Open
richardjgowers opened this Issue Jul 14, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@richardjgowers
Member

richardjgowers commented Jul 14, 2017

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.

Related discussion here

@richardjgowers

This comment has been minimized.

Show comment
Hide comment
@richardjgowers

richardjgowers Jul 14, 2017

Member

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]
Member

richardjgowers commented Jul 14, 2017

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment