Skip to content

Commit

Permalink
Skip pgsql tests if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 committed Feb 9, 2024
1 parent b3b3e14 commit 1013429
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
26 changes: 11 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
except FileNotFoundError:
TEST_DATA_BIG = None # skip benchmark tests

SKIP_PGSQL_TESTS = False
try:
mp = Platform(_backend=PostgresTestBackend())
# TODO: Do we need the following?
# mp.backend.close()
except OperationalError:
SKIP_PGSQL_TESTS = True


@pytest.fixture(scope="function")
def test_data_big():
Expand Down Expand Up @@ -104,13 +112,7 @@ def test_sqlite_mp():

@pytest.fixture
def test_pgsql_mp():
try:
mp = Platform(_backend=PostgresTestBackend())
except OperationalError as e:
pytest.skip(
f"Cannot connect to PostgreSQL database service, skipping test: {e}"
)

mp = Platform(_backend=PostgresTestBackend())
yield mp
mp.backend.close()

Expand All @@ -133,14 +135,8 @@ def test_sqlite_mp_generated():


@pytest.fixture(scope="module")
def test_pgsql_mp_generated():
try:
mp = Platform(_backend=PostgresTestBackend())
except OperationalError as e:
pytest.skip(
f"Cannot connect to PostgreSQL database service, skipping test: {e}"
)

def test_pgsql_mp_generated(request):
mp = Platform(_backend=PostgresTestBackend())
generate_mock_data(mp)
yield mp
mp.backend.close()
Expand Down
50 changes: 44 additions & 6 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from ixmp4 import DataPoint

from .conftest import SKIP_PGSQL_TESTS


def add_regions(mp, regions):
for region in regions:
Expand All @@ -27,19 +29,43 @@ def assert_unordered_equality(df1, df2, **kwargs):
"test_mp",
[
"test_sqlite_mp",
"test_pgsql_mp",
pytest.param(
"test_pgsql_mp",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
"test_api_sqlite_mp",
"test_api_pgsql_mp",
pytest.param(
"test_api_pgsql_mp",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
],
)

generated_platforms = pytest.mark.parametrize(
"generated_mp",
[
"test_sqlite_mp_generated",
"test_pgsql_mp_generated",
pytest.param(
"test_pgsql_mp_generated",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
"test_api_sqlite_mp_generated",
"test_api_pgsql_mp_generated",
pytest.param(
"test_api_pgsql_mp_generated",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
],
)

Expand All @@ -48,15 +74,27 @@ def assert_unordered_equality(df1, df2, **kwargs):
"test_mp",
[
"test_api_sqlite_mp",
"test_api_pgsql_mp",
pytest.param(
"test_api_pgsql_mp",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
],
)

database_platforms = pytest.mark.parametrize(
"test_mp",
[
"test_sqlite_mp",
"test_pgsql_mp",
pytest.param(
"test_pgsql_mp",
marks=pytest.mark.skipif(
SKIP_PGSQL_TESTS,
reason="Cannot connect to PostgreSQL database service, skipping test",
),
),
],
)

Expand Down

0 comments on commit 1013429

Please sign in to comment.