Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ def pytest_generate_tests(metafunc):
if "pgmq_all_variants" in metafunc.fixturenames:
driver_from_cli = metafunc.config.getoption("--driver")

# Define sync and async fixture variants
# Define sync fixture variants
# pgmq_all_variants is only for sync drivers because the dependent fixtures
# (pgmq_setup_teardown, pgmq_partitioned_setup_teardown) call methods like
# create_queue() and drop_queue() directly without await, which would fail
# with async PGMQ instances
sync_fixtures = [
'pgmq_by_dsn',
'pgmq_by_engine',
Expand All @@ -47,29 +51,25 @@ def pytest_generate_tests(metafunc):
'pgmq_by_dsn_and_session_maker',
]

async_fixtures = [
'pgmq_by_async_dsn',
'pgmq_by_async_engine',
'pgmq_by_async_session_maker',
]

# Determine which fixtures to use
if not driver_from_cli:
# No driver specified, use all fixtures
fixture_params = sync_fixtures + async_fixtures
# No driver specified, use only sync fixtures
fixture_params = sync_fixtures
elif driver_from_cli in ASYNC_DRIVERS:
# Async driver specified
fixture_params = async_fixtures
# Async driver specified, skip tests using pgmq_all_variants
# (empty fixture list will cause pytest to skip these tests)
fixture_params = []
else:
# Sync driver specified
fixture_params = sync_fixtures

# Parametrize the test
metafunc.parametrize(
"pgmq_all_variants",
fixture_params,
indirect=True
)
# Only parametrize if there are fixtures to use
if fixture_params:
metafunc.parametrize(
"pgmq_all_variants",
fixture_params,
indirect=True
)


@pytest.fixture(scope="module")
Expand Down
12 changes: 8 additions & 4 deletions tests/fixture_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@
@pytest.fixture(scope="function")
def pgmq_all_variants(request: pytest.FixtureRequest) -> PGMQueue:
"""
Fixture that parametrizes tests across all appropriate PGMQueue initialization methods.
Fixture that parametrizes tests across all appropriate PGMQueue sync initialization methods.

When --driver is specified, only fixtures matching that driver type (sync/async) are used.
Without --driver, all fixtures are used.
Note: This fixture only provides sync driver variants. Async driver tests should use
async fixtures directly (pgmq_by_async_dsn, pgmq_by_async_engine, pgmq_by_async_session_maker).

When --driver is specified as a sync driver, only fixtures matching that driver are used.
When --driver is specified as an async driver, tests using this fixture are skipped.
Without --driver, only sync fixtures are used.

The parametrization is handled by pytest_generate_tests in conftest.py.

Usage:
def test_something(pgmq_all_variants):
pgmq: PGMQueue = pgmq_all_variants
# test code here
# test code here (sync methods only)
"""
# The param is set by pytest_generate_tests via indirect parametrization
return request.getfixturevalue(request.param)
Expand Down