Skip to content

Commit

Permalink
Fixtures: Make pgtest truly an optional dependency (#6502)
Browse files Browse the repository at this point in the history
The pytest fixtures were improved to allow running with a
`core.sqlite_dos` storage for the test profile, making PostgreSQL
completely optional. However, the current fixture still imports the
`pgtest` package at module level making it a requirement, despite it
only being relevant when running the tests with a `core.psql_dos`
storage plugin.

Here the import is moved inside the `PostgresCluster._create` method
which is only called when the test suite actually uses a PSQL based
storage plugin.
  • Loading branch information
sphuber authored Jul 1, 2024
1 parent 2ccfeee commit 9fe8fd2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/aiida/tools/pytest_fixtures/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from uuid import uuid4

import pytest
from pgtest.pgtest import PGTest

if t.TYPE_CHECKING:
from pgtest.pgtest import PGTest
Expand All @@ -19,6 +18,8 @@ def __init__(self):
self.cluster = None

def _create(self):
from pgtest.pgtest import PGTest

try:
self.cluster = PGTest()
except OSError as e:
Expand Down Expand Up @@ -59,7 +60,6 @@ def create_database(
return postgres_config


# TODO: Update docstring accordingly
@pytest.fixture(scope='session')
def postgres_cluster():
"""Create a temporary and isolated PostgreSQL cluster using ``pgtest`` and cleanup after the yield.
Expand Down

0 comments on commit 9fe8fd2

Please sign in to comment.