Mercurial > p > roundup > code
comparison test/test_postgresql.py @ 7841:673bb9cb41b4
test: fix ImportError if psycopg2 not installed
test_postgresql was reaching into roundup.backends.back_postgresql
before checking to see if psycopg2 was available. Move the (partly
duplicated) import inside the guard so it imports only if psycopg2 is
available.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 26 Mar 2024 22:35:24 -0400 |
| parents | 8147f6deac9f |
| children |
comparison
equal
deleted
inserted
replaced
| 7840:ce740d9a7d8d | 7841:673bb9cb41b4 |
|---|---|
| 19 import unittest | 19 import unittest |
| 20 import pytest | 20 import pytest |
| 21 | 21 |
| 22 from roundup.hyperdb import DatabaseError | 22 from roundup.hyperdb import DatabaseError |
| 23 from roundup.backends import get_backend, have_backend | 23 from roundup.backends import get_backend, have_backend |
| 24 from roundup.backends.back_postgresql import db_command, get_database_schema_names | |
| 25 | 24 |
| 26 from .db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest | 25 from .db_test_base import DBTest, ROTest, config, SchemaTest, ClassicInitTest |
| 27 from .db_test_base import ConcurrentDBTest, HTMLItemTest, FilterCacheTest | 26 from .db_test_base import ConcurrentDBTest, HTMLItemTest, FilterCacheTest |
| 28 from .db_test_base import ClassicInitBase, setupTracker, SpecialActionTest | 27 from .db_test_base import ClassicInitBase, setupTracker, SpecialActionTest |
| 29 from .rest_common import TestCase as RestTestCase | 28 from .rest_common import TestCase as RestTestCase |
| 34 from .pytest_patcher import mark_class | 33 from .pytest_patcher import mark_class |
| 35 skip_postgresql = mark_class(pytest.mark.skip( | 34 skip_postgresql = mark_class(pytest.mark.skip( |
| 36 reason='Skipping PostgreSQL tests: backend not available')) | 35 reason='Skipping PostgreSQL tests: backend not available')) |
| 37 else: | 36 else: |
| 38 try: | 37 try: |
| 39 from roundup.backends.back_postgresql import psycopg2, db_command | 38 from roundup.backends.back_postgresql import psycopg2, db_command,\ |
| 39 get_database_schema_names | |
| 40 db_command(config, 'select 1') | 40 db_command(config, 'select 1') |
| 41 skip_postgresql = lambda func, *args, **kwargs: func | 41 skip_postgresql = lambda func, *args, **kwargs: func |
| 42 except( DatabaseError ) as msg: | 42 except( DatabaseError ) as msg: |
| 43 from .pytest_patcher import mark_class | 43 from .pytest_patcher import mark_class |
| 44 skip_postgresql = mark_class(pytest.mark.skip( | 44 skip_postgresql = mark_class(pytest.mark.skip( |
