Skip to content

Commit 573e102

Browse files
committed
test_postgress isn't properly skipping tests when database is not
accessible. Trying to use the model from test_mysql to see that properly skips the postgres tests.
1 parent ca10fde commit 573e102

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

test/test_postgresql.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,29 @@
1919

2020
import pytest
2121
from roundup.hyperdb import DatabaseError
22+
from roundup.backends import get_backend, have_backend
2223

2324
from db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest
2425
from db_test_base import ConcurrentDBTest, HTMLItemTest, FilterCacheTest
2526
from db_test_base import ClassicInitBase, setupTracker
2627

27-
from roundup.backends import get_backend, have_backend
28-
from roundup.backends.back_postgresql import psycopg
29-
3028
if not have_backend('postgresql'):
3129
# FIX: workaround for a bug in pytest.mark.skip():
3230
# https://github.com/pytest-dev/pytest/issues/568
3331
from .pytest_patcher import mark_class
3432
skip_postgresql = mark_class(pytest.mark.skip(
3533
reason='Skipping PostgreSQL tests: backend not available'))
3634
else:
37-
skip_postgresql = lambda func, *args, **kwargs: func
38-
35+
try:
36+
from roundup.backends.back_postgresql import psycopg, db_command
37+
db_command(config, 'select 1')
38+
skip_postgresql = lambda func, *args, **kwargs: func
39+
except( DatabaseError ) as msg:
40+
from .pytest_patcher import mark_class
41+
skip_postgresql = mark_class(pytest.mark.skip(
42+
reason='Skipping PostgreSQL tests: database not available'))
3943

44+
@skip_postgresql
4045
class postgresqlOpener:
4146
if have_backend('postgresql'):
4247
module = get_backend('postgresql')

0 commit comments

Comments
 (0)