diff --git a/tests/conftest.py b/tests/conftest.py index 5a65cb7..3797ee2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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', @@ -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") diff --git a/tests/fixture_deps.py b/tests/fixture_deps.py index b1bc6e8..88fe527 100644 --- a/tests/fixture_deps.py +++ b/tests/fixture_deps.py @@ -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)