From: Daniele Varrazzo Date: Thu, 6 Jan 2022 23:23:46 +0000 (+0100) Subject: Add mark for pool tests X-Git-Tag: pool-3.1~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a8bb1bc68301f1d2105fe8885485eca6b2be59f;p=thirdparty%2Fpsycopg.git Add mark for pool tests Don't auto-skip pool test if import fails. This would miss serious problems leading to the pool not being importable. If someone wants to skip the pool tests they can use `-m 'not pool'` now. --- diff --git a/tests/conftest.py b/tests/conftest.py index 96331e903..588fa8aff 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,35 +11,23 @@ pytest_plugins = ( "tests.fix_faker", "tests.fix_proxy", "tests.fix_psycopg", + "tests.pool.fix_pool", ) def pytest_configure(config): - # register slow marker - config.addinivalue_line( - "markers", "slow: this test is kinda slow (skip with -m 'not slow')" - ) - - # There are troubles on travis with these kind of tests and I cannot - # catch the exception for my life. - config.addinivalue_line( - "markers", "subprocess: the test import psycopg after subprocess" - ) - - config.addinivalue_line( - "markers", + markers = [ + "slow: this test is kinda slow (skip with -m 'not slow')", + # There are troubles on travis with these kind of tests and I cannot + # catch the exception for my life. + "subprocess: the test import psycopg after subprocess", "timing: the test is timing based and can fail on cheese hardware", - ) - - config.addinivalue_line( - "markers", "dns: the test requires dnspython to run", - ) - - config.addinivalue_line( - "markers", "postgis: the test requires the PostGIS extension to run", - ) + ] + + for marker in markers: + config.addinivalue_line("markers", marker) def pytest_addoption(parser): diff --git a/tests/pool/fix_pool.py b/tests/pool/fix_pool.py new file mode 100644 index 000000000..13768c092 --- /dev/null +++ b/tests/pool/fix_pool.py @@ -0,0 +1,14 @@ +import pytest + + +def pytest_configure(config): + config.addinivalue_line( + "markers", "pool: test related to the psycopg_pool package" + ) + + +def pytest_collection_modifyitems(items): + # Add the pool markers to all the tests in the pool package + for item in items: + if "/pool/" in item.nodeid: + item.add_marker(pytest.mark.pool) diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 14297cdbf..45cc33b4e 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -11,14 +11,11 @@ import psycopg from psycopg.pq import TransactionStatus from psycopg._compat import Counter -pytestmark = [] - try: - from psycopg_pool import ConnectionPool # noqa: F401 -except ImportError as ex: - pytestmark.append(pytest.mark.skip(reason=str(ex))) -else: import psycopg_pool as pool +except ImportError: + # Tests should have been skipped if the package is not available + pass def test_package_version(mypy): diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 7d75d7ba6..923fb84e0 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -10,6 +10,12 @@ import psycopg from psycopg.pq import TransactionStatus from psycopg._compat import create_task, Counter +try: + import psycopg_pool as pool +except ImportError: + # Tests should have been skipped if the package is not available + pass + pytestmark = [ pytest.mark.asyncio, pytest.mark.skipif( @@ -18,13 +24,6 @@ pytestmark = [ ), ] -try: - from psycopg_pool import AsyncConnectionPool # noqa: F401 -except ImportError as ex: - pytestmark.append(pytest.mark.skip(reason=str(ex))) -else: - import psycopg_pool as pool - async def test_defaults(dsn): async with pool.AsyncConnectionPool(dsn) as p: diff --git a/tests/pool/test_sched.py b/tests/pool/test_sched.py index a3bdd5cfa..abdb97e9e 100644 --- a/tests/pool/test_sched.py +++ b/tests/pool/test_sched.py @@ -5,12 +5,13 @@ from threading import Thread import pytest -pytestmark = [pytest.mark.timing] - try: from psycopg_pool.sched import Scheduler -except ImportError as ex: - pytestmark.append(pytest.mark.skip(reason=str(ex))) +except ImportError: + # Tests should have been skipped if the package is not available + pass + +pytestmark = [pytest.mark.timing] @pytest.mark.slow diff --git a/tests/pool/test_sched_async.py b/tests/pool/test_sched_async.py index 651e9038f..6c3e23d7b 100644 --- a/tests/pool/test_sched_async.py +++ b/tests/pool/test_sched_async.py @@ -7,12 +7,13 @@ import pytest from psycopg._compat import create_task -pytestmark = [pytest.mark.asyncio, pytest.mark.timing] - try: from psycopg_pool.sched import AsyncScheduler -except ImportError as ex: - pytestmark.append(pytest.mark.skip(reason=str(ex))) +except ImportError: + # Tests should have been skipped if the package is not available + pass + +pytestmark = [pytest.mark.asyncio, pytest.mark.timing] @pytest.mark.slow