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 | ||||
from _pytest.fixtures import FixtureRequest | |||||
import psycopg2 | import psycopg2 | ||||
import pytest | import pytest | ||||
from pytest_postgresql import factories | from pytest_postgresql import factories | ||||
from pytest_postgresql.janitor import DatabaseJanitor, Version | from pytest_postgresql.janitor import DatabaseJanitor, Version | ||||
from swh.core.utils import numfile_sortkey as sortkey | from swh.core.utils import numfile_sortkey as sortkey | ||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | |||||
# specify our version of the DBJanitor we use. | # specify our version of the DBJanitor we use. | ||||
def postgresql_fact( | def postgresql_fact( | ||||
process_fixture_name: str, | process_fixture_name: str, | ||||
db_name: Optional[str] = None, | db_name: Optional[str] = None, | ||||
dump_files: str = "", | dump_files: str = "", | ||||
no_truncate_tables: Set[str] = {"dbversion"}, | no_truncate_tables: Set[str] = {"dbversion"}, | ||||
): | ): | ||||
@pytest.fixture | @pytest.fixture | ||||
def postgresql_factory(request): | def postgresql_factory(request: FixtureRequest): | ||||
"""Fixture factory for PostgreSQL. | """Fixture factory for PostgreSQL. | ||||
:param FixtureRequest request: fixture request object | :param FixtureRequest request: fixture request object | ||||
:rtype: psycopg2.connection | :rtype: psycopg2.connection | ||||
:returns: postgresql client | :returns: postgresql client | ||||
""" | """ | ||||
config = factories.get_config(request) | config = factories.get_config(request) | ||||
proc_fixture = request.getfixturevalue(process_fixture_name) | proc_fixture = request.getfixturevalue(process_fixture_name) | ||||
Show All 26 Lines |