Changeset View
Changeset View
Standalone View
Standalone View
swh/core/db/pytest_plugin.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import glob | import glob | ||||
import logging | import logging | ||||
import subprocess | import subprocess | ||||
from typing import Optional, Set, Union | from typing import Optional, Set, Union | ||||
import psycopg2 | import psycopg2 | ||||
import pytest | import pytest | ||||
from swh.core.utils import numfile_sortkey as sortkey | |||||
try: | |||||
from pytest_postgresql import factories | from pytest_postgresql import factories | ||||
from pytest_postgresql.janitor import DatabaseJanitor, Version | from pytest_postgresql.janitor import DatabaseJanitor, Version | ||||
except ImportError: | |||||
error_msg = "The module pytest_plugin requires dependency pytest-postgresql module" | |||||
raise EnvironmentError(error_msg) | |||||
from swh.core.utils import numfile_sortkey as sortkey | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
class SWHDatabaseJanitor(DatabaseJanitor): | class SWHDatabaseJanitor(DatabaseJanitor): | ||||
"""SWH database janitor implementation with a a different setup/teardown policy than | """SWH database janitor implementation with a a different setup/teardown policy than | ||||
than the stock one. Instead of dropping, creating and initializing the database for | than the stock one. Instead of dropping, creating and initializing the database for | ||||
each test, it creates and initializes the db once, then truncates the tables (and | each test, it creates and initializes the db once, then truncates the tables (and | ||||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |