Skip to content
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

Refactor fixtures to allow for different scopes #6738

Open
GeigerJ2 opened this issue Jan 29, 2025 · 0 comments
Open

Refactor fixtures to allow for different scopes #6738

GeigerJ2 opened this issue Jan 29, 2025 · 0 comments
Labels
type/feature request status undecided

Comments

@GeigerJ2
Copy link
Contributor

Currently, many of the fixtures in AiiDA, such as aiida_localhost (here) are function-scoped (which is the pytest default). It would be nice to have a way to also use them at different scopes, e.g., class-scoped, for expensive setup-operations that should only be carried out once for a test class, for example.

One idea to allow this, originally brought up by @agoscinski on Slack, is to put the functionality currently contained in the fixtures into utility functions, which are then used by differently scoped fixtures, like:

# the logic that was in aiida_localhost is moved here
def utils_aiida_localhost(...):
    ...

# new fixture only class scope
@pytest.fixture(scope="class")
def aiida_localhost_class(...):
    utils_aiida_localhost(...)

# original fixture
@pytest.fixture(scope="function")  # Currently the default, even without explicitly specifying `scope="function"`
def aiida_localhost(...):  # or `aiida_localhost_function`, but backwards-incompatible
    utils_aiida_localhost(...)

To achieve this, a few other changes might also be necessary, as, e.g., tmp_path provided by pytest is also function scoped, so cannot be used in a class- or session-scoped fixture (instead, pytest provides the session-scoped tmp_path_factory fixture).

@GeigerJ2 GeigerJ2 added the type/feature request status undecided label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature request status undecided
Projects
None yet
Development

No branches or pull requests

1 participant