From 4e47f3e649e1fb30a5e9ccb7cbdba1694af56e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= Date: Wed, 17 May 2023 17:23:24 +0200 Subject: [PATCH] Replace flake8 and pydocstyle with ruff - closes #735 --- .github/workflows/linters.yml | 19 ++----- Pipfile | 3 +- Pipfile.lock | 52 +++++++++---------- newsfragments/735.misc.rst | 1 + pyproject.toml | 11 +++- pytest_postgresql/compat.py | 11 ++-- pytest_postgresql/config.py | 2 +- pytest_postgresql/executor.py | 13 ++--- pytest_postgresql/executor_noop.py | 8 ++- pytest_postgresql/factories/__init__.py | 4 +- pytest_postgresql/factories/client.py | 10 ++-- pytest_postgresql/factories/noprocess.py | 8 ++- pytest_postgresql/factories/process.py | 10 ++-- pytest_postgresql/janitor.py | 10 ++-- pytest_postgresql/plugin.py | 2 +- pytest_postgresql/retry.py | 6 +-- setup.cfg | 3 -- tests/conftest.py | 2 +- ...ooproc_docker.py => test_noproc_docker.py} | 5 +- tests/examples/test_postgres_options.py | 6 ++- tests/test_executor.py | 9 ++-- tests/test_janitor.py | 6 +-- tests/test_noopexecutor.py | 5 +- tests/test_postgres_options_plugin.py | 3 +- tests/test_postgresql.py | 6 +-- tests/test_template_database.py | 2 +- 26 files changed, 93 insertions(+), 124 deletions(-) create mode 100644 newsfragments/735.misc.rst delete mode 100644 setup.cfg rename tests/docker/{test_nooproc_docker.py => test_noproc_docker.py} (95%) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 7a97bb29..850de97b 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -9,25 +9,12 @@ on: jobs: lint: - uses: fizyk/actions-reuse/.github/workflows/linters-python.yml@v1.7.1 + uses: fizyk/actions-reuse/.github/workflows/linters-python.yml@v2.0.0 with: - pipenv: true pipenv-install-options: "--skip-lock" mypy: true - pycodestyle: false - flake8: - runs-on: ubuntu-latest - strategy: - fail-fast: false - - steps: - - uses: actions/checkout@v3 - - name: Run flake8 checker - uses: fizyk/actions-reuse/.github/actions/pipenv@v1.7.1 - with: - python-version: ${{ matrix.python-version }} - pipenv-install-options: "--skip-lock" - command: flake8 pytest_postgresql/ tests/ + ruff: true + black: true # imports: diff --git a/Pipfile b/Pipfile index 85252cf5..72ccad38 100644 --- a/Pipfile +++ b/Pipfile @@ -14,12 +14,11 @@ towncrier = "==22.12" pytest-cov = "==4.0.0" pytest-xdist = "==3.3.0" mock = "==5.0.2" -pydocstyle = {version = "==6.3.0", extras = ["toml"]} black = "==23.3.0" mypy = "==1.3.0" pyflakes = "==2.5.0" mccabe = "==0.7.0" -flake8 = "==5.0.4" types-setuptools = "==67.7.0.2" pycodestyle = "==2.9.0" tbump = "==6.9.0" +ruff = "==0.0.267" diff --git a/Pipfile.lock b/Pipfile.lock index a77ae04c..95eecb6c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ba6308c0a5e79670421dce4d5f899d35835a4f1a4e8e80f09345e3c92c5e2918" + "sha256": "999dfc5fc6dee4a08b3d9a68799c16788aeb434be380069656f0df931ae49ac7" }, "pipfile-spec": 6, "requires": {}, @@ -243,14 +243,6 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==1.9.0" }, - "flake8": { - "hashes": [ - "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db", - "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248" - ], - "index": "pypi", - "version": "==5.0.4" - }, "incremental": { "hashes": [ "sha256:912feeb5e0f7e0188e6f42241d2f450002e11bbc0937c65865045854c24c0bd0", @@ -426,18 +418,6 @@ "index": "pypi", "version": "==2.9.0" }, - "pydocstyle": { - "extras": [ - "toml" - ], - "hashes": [ - "sha256:118762d452a49d6b05e194ef344a55822987a462831ade91ec5c06fd2169d019", - "sha256:7ce43f0c0ac87b07494eb9c0b462c0b73e6ff276807f204d6b53edc72b7e44e1" - ], - "index": "pypi", - "markers": null, - "version": "==6.3.0" - }, "pyflakes": { "hashes": [ "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2", @@ -470,6 +450,29 @@ "index": "pypi", "version": "==3.3.0" }, + "ruff": { + "hashes": [ + "sha256:0afca3633c8e2b6c0a48ad0061180b641b3b404d68d7e6736aab301c8024c424", + "sha256:20c594eb56c19063ef5a57f89340e64c6550e169d6a29408a45130a8c3068adc", + "sha256:2107cec3699ca4d7bd41543dc1d475c97ae3a21ea9212238b5c2088fa8ee7722", + "sha256:2972241065b1c911bce3db808837ed10f4f6f8a8e15520a4242d291083605ab6", + "sha256:45d61a2b01bdf61581a2ee039503a08aa603dc74a6bbe6fb5d1ce3052f5370e5", + "sha256:4adbbbe314d8fcc539a245065bad89446a3cef2e0c9cf70bf7bb9ed6fe31856d", + "sha256:5a898953949e37c109dd242cfcf9841e065319995ebb7cdfd213b446094a942f", + "sha256:632cec7bbaf3c06fcf0a72a1dd029b7d8b7f424ba95a574aaa135f5d20a00af7", + "sha256:67254ae34c38cba109fdc52e4a70887de1f850fb3971e5eeef343db67305d1c1", + "sha256:786de30723c71fc46b80a173c3313fc0dbe73c96bd9da8dd1212cbc2f84cdfb2", + "sha256:7df7eb5f8d791566ba97cc0b144981b9c080a5b861abaf4bb35a26c8a77b83e9", + "sha256:9adf1307fa9d840d1acaa477eb04f9702032a483214c409fca9dc46f5f157fe3", + "sha256:bbe104f21a429b77eb5ac276bd5352fd8c0e1fbb580b4c772f77ee8c76825654", + "sha256:d09aecc9f5845586ba90911d815f9772c5a6dcf2e34be58c6017ecb124534ac4", + "sha256:d12ab329474c46b96d962e2bdb92e3ad2144981fe41b89c7770f370646c0101f", + "sha256:db33deef2a5e1cf528ca51cc59dd764122a48a19a6c776283b223d147041153f", + "sha256:f731d81cb939e757b0335b0090f18ca2e9ff8bcc8e6a1cf909245958949b6e11" + ], + "index": "pypi", + "version": "==0.0.267" + }, "schema": { "hashes": [ "sha256:f06717112c61895cabc4707752b88716e8420a8819d71404501e114f91043197", @@ -485,13 +488,6 @@ "markers": "python_version >= '3.7'", "version": "==67.7.2" }, - "snowballstemmer": { - "hashes": [ - "sha256:09b16deb8547d3412ad7b590689584cd0fe25ec8db3be37788be3810cbf19cb1", - "sha256:c8e1716e83cc398ae16824e5572ae04e0d9fc2c6b985fb0f900f5f0c96ecba1a" - ], - "version": "==2.2.0" - }, "tabulate": { "hashes": [ "sha256:0ba055423dbaa164b9e456abe7920c5e8ed33fcc16f6d1b2f2d152c8e1e8b4fc", diff --git a/newsfragments/735.misc.rst b/newsfragments/735.misc.rst new file mode 100644 index 00000000..bf678f8e --- /dev/null +++ b/newsfragments/735.misc.rst @@ -0,0 +1 @@ +Replaced flake8 and pydocstyle with ruff, turned on isort rules \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index b806970b..d9e57934 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,8 +66,15 @@ line-length = 100 target-version = ['py39'] include = '.*\.pyi?$' -[tool.pydocstyle] -ignore = "D203,D212" +[tool.ruff] +# Decrease the maximum line length to 79 characters. +line-length = 100 +select = [ + "E", # pycodestyle + "F", # pyflakes + "I", # isort + "D", # pydocstyle +] [tool.towncrier] directory = "newsfragments" diff --git a/pytest_postgresql/compat.py b/pytest_postgresql/compat.py index abff3b11..3fc5a07f 100644 --- a/pytest_postgresql/compat.py +++ b/pytest_postgresql/compat.py @@ -1,12 +1,10 @@ -""" -psycopg compatibility module. +"""psycopg compatibility module. It should be possible to import pytest-postgresql without errors when psycopg is not installed (while tests using it will error or be skipped). So import psycopg only here and check if it's available. """ -from typing import Any, TYPE_CHECKING - +from typing import TYPE_CHECKING, Any __all__ = ("psycopg", "cursor", "connection", "check_for_psycopg") @@ -21,13 +19,12 @@ connection = Any else: - from psycopg import Cursor as cursor from psycopg import Connection as connection + from psycopg import Cursor as cursor def check_for_psycopg() -> None: - """ - Check whether psycopg was imported. + """Check whether psycopg was imported. Raises ImportError if not. """ diff --git a/pytest_postgresql/config.py b/pytest_postgresql/config.py index 9d27f229..8c8e0214 100644 --- a/pytest_postgresql/config.py +++ b/pytest_postgresql/config.py @@ -1,5 +1,5 @@ """Plugin's configuration.""" -from typing import Optional, TypedDict, Any, List +from typing import Any, List, Optional, TypedDict from pytest import FixtureRequest diff --git a/pytest_postgresql/executor.py b/pytest_postgresql/executor.py index 0efbe5bf..e3811712 100644 --- a/pytest_postgresql/executor.py +++ b/pytest_postgresql/executor.py @@ -24,11 +24,11 @@ import subprocess import tempfile import time -from typing import TypeVar, Optional, Any +from typing import Any, Optional, TypeVar -from pkg_resources import parse_version from mirakuru import TCPExecutor from mirakuru.exceptions import ProcessFinishedWithError +from pkg_resources import parse_version _LOCALE = "C.UTF-8" @@ -44,8 +44,7 @@ class PostgreSQLUnsupported(Exception): class PostgreSQLExecutor(TCPExecutor): - """ - PostgreSQL executor running on pg_ctl. + """PostgreSQL executor running on pg_ctl. Based over an `pg_ctl program `_ @@ -80,8 +79,7 @@ def __init__( options: str = "", postgres_options: str = "", ): - """ - Initialize PostgreSQLExecutor executor. + """Initialize PostgreSQLExecutor executor. :param executable: pg_ctl location :param host: host under which process is accessible @@ -153,8 +151,7 @@ def clean_directory(self) -> None: self._directory_initialised = False def init_directory(self) -> None: - """ - Initialize postgresql data directory. + """Initialize postgresql data directory. See `Initialize postgresql data directory `_ diff --git a/pytest_postgresql/executor_noop.py b/pytest_postgresql/executor_noop.py index 2ca6c846..0368211b 100644 --- a/pytest_postgresql/executor_noop.py +++ b/pytest_postgresql/executor_noop.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with pytest-dbfixtures. If not, see . """PostgreSQL Noop executor providing connection details for postgres client.""" -from typing import Union, Optional, Any +from typing import Any, Optional, Union from pkg_resources import parse_version @@ -24,8 +24,7 @@ class NoopExecutor: - """ - Nooperator executor. + """Nooperator executor. This executor actually does nothing more than provide connection details for existing PostgreSQL server. I.E. one already started either on machine @@ -41,8 +40,7 @@ def __init__( dbname: str, password: Optional[str] = None, ): - """ - Initialize nooperator executor mock. + """Initialize nooperator executor mock. :param host: Postgresql hostname :param port: Postgresql port diff --git a/pytest_postgresql/factories/__init__.py b/pytest_postgresql/factories/__init__.py index c2a7eaaa..613173cb 100644 --- a/pytest_postgresql/factories/__init__.py +++ b/pytest_postgresql/factories/__init__.py @@ -17,8 +17,8 @@ # along with pytest-dbfixtures. If not, see . """Fixture factories for postgresql fixtures.""" -from pytest_postgresql.factories.process import postgresql_proc -from pytest_postgresql.factories.noprocess import postgresql_noproc from pytest_postgresql.factories.client import postgresql +from pytest_postgresql.factories.noprocess import postgresql_noproc +from pytest_postgresql.factories.process import postgresql_proc __all__ = ("postgresql_proc", "postgresql_noproc", "postgresql") diff --git a/pytest_postgresql/factories/client.py b/pytest_postgresql/factories/client.py index 979f0b60..a025c118 100644 --- a/pytest_postgresql/factories/client.py +++ b/pytest_postgresql/factories/client.py @@ -16,12 +16,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with pytest-dbfixtures. If not, see . """Fixture factory for postgresql client.""" -from typing import List, Optional, Callable, Union, Iterator +from typing import Callable, Iterator, List, Optional, Union import pytest from pytest import FixtureRequest -from pytest_postgresql.compat import connection, check_for_psycopg, psycopg +from pytest_postgresql.compat import check_for_psycopg, connection, psycopg from pytest_postgresql.executor import PostgreSQLExecutor from pytest_postgresql.executor_noop import NoopExecutor from pytest_postgresql.janitor import DatabaseJanitor @@ -33,8 +33,7 @@ def postgresql( load: Optional[List[Union[Callable, str]]] = None, isolation_level: "Optional[psycopg.IsolationLevel]" = None, ) -> Callable[[FixtureRequest], Iterator[connection]]: - """ - Return connection fixture factory for PostgreSQL. + """Return connection fixture factory for PostgreSQL. :param process_fixture_name: name of the process fixture :param dbname: database name @@ -47,8 +46,7 @@ def postgresql( @pytest.fixture def postgresql_factory(request: FixtureRequest) -> Iterator[connection]: - """ - Fixture factory for PostgreSQL. + """Fixture factory for PostgreSQL. :param request: fixture request object :returns: postgresql client diff --git a/pytest_postgresql/factories/noprocess.py b/pytest_postgresql/factories/noprocess.py index e477c7ed..e61bb31d 100644 --- a/pytest_postgresql/factories/noprocess.py +++ b/pytest_postgresql/factories/noprocess.py @@ -17,7 +17,7 @@ # along with pytest-dbfixtures. If not, see . """Fixture factory for existing postgresql server.""" import os -from typing import Union, Callable, List, Iterator, Optional +from typing import Callable, Iterator, List, Optional, Union import pytest from pytest import FixtureRequest @@ -44,8 +44,7 @@ def postgresql_noproc( options: str = "", load: Optional[List[Union[Callable, str]]] = None, ) -> Callable[[FixtureRequest], Iterator[NoopExecutor]]: - """ - Postgresql noprocess factory. + """Postgresql noprocess factory. :param host: hostname :param port: exact port (e.g. '8000', 8000) @@ -59,8 +58,7 @@ def postgresql_noproc( @pytest.fixture(scope="session") def postgresql_noproc_fixture(request: FixtureRequest) -> Iterator[NoopExecutor]: - """ - Noop Process fixture for PostgreSQL. + """Noop Process fixture for PostgreSQL. :param request: fixture request object :returns: tcp executor-like object diff --git a/pytest_postgresql/factories/process.py b/pytest_postgresql/factories/process.py index d178f3bb..20562ddd 100644 --- a/pytest_postgresql/factories/process.py +++ b/pytest_postgresql/factories/process.py @@ -19,12 +19,12 @@ import os.path import platform import subprocess -from typing import Union, Callable, List, Iterator, Optional, Tuple, Set +from typing import Callable, Iterator, List, Optional, Set, Tuple, Union from warnings import warn import pytest -from pytest import FixtureRequest, TempPathFactory from port_for import get_port +from pytest import FixtureRequest, TempPathFactory from pytest_postgresql.config import get_config from pytest_postgresql.executor import PostgreSQLExecutor @@ -57,8 +57,7 @@ def postgresql_proc( postgres_options: Optional[str] = None, load: Optional[List[Union[Callable, str]]] = None, ) -> Callable[[FixtureRequest, TempPathFactory], Iterator[PostgreSQLExecutor]]: - """ - Postgresql process factory. + """Postgresql process factory. :param executable: path to postgresql_ctl :param host: hostname @@ -85,8 +84,7 @@ def postgresql_proc( def postgresql_proc_fixture( request: FixtureRequest, tmp_path_factory: TempPathFactory ) -> Iterator[PostgreSQLExecutor]: - """ - Process fixture for PostgreSQL. + """Process fixture for PostgreSQL. :param request: fixture request object :param tmp_path_factory: temporary path object (fixture) diff --git a/pytest_postgresql/janitor.py b/pytest_postgresql/janitor.py index 0bbe77fd..4272c924 100644 --- a/pytest_postgresql/janitor.py +++ b/pytest_postgresql/janitor.py @@ -3,11 +3,11 @@ from contextlib import contextmanager from functools import partial from types import TracebackType -from typing import TypeVar, Union, Optional, Type, Callable, Iterator +from typing import Callable, Iterator, Optional, Type, TypeVar, Union from pkg_resources import parse_version -from pytest_postgresql.compat import psycopg, cursor, check_for_psycopg, connection +from pytest_postgresql.compat import check_for_psycopg, connection, cursor, psycopg from pytest_postgresql.retry import retry from pytest_postgresql.sql import loader @@ -31,8 +31,7 @@ def __init__( isolation_level: "Optional[psycopg.IsolationLevel]" = None, connection_timeout: int = 60, ) -> None: - """ - Initialize janitor. + """Initialize janitor. :param user: postgresql username :param host: postgresql host @@ -105,8 +104,7 @@ def _terminate_connection(cur: cursor, dbname: str) -> None: ) def load(self, load: Union[Callable, str]) -> None: - """ - Load data into a database. + """Load data into a database. Either runs a passed loader if it's callback, or runs predefined loader if it's sql file. diff --git a/pytest_postgresql/plugin.py b/pytest_postgresql/plugin.py index 0262e430..ac92fef2 100644 --- a/pytest_postgresql/plugin.py +++ b/pytest_postgresql/plugin.py @@ -18,9 +18,9 @@ """Plugin module of pytest-postgresql.""" from tempfile import gettempdir -from pytest_postgresql import factories from _pytest.config.argparsing import Parser +from pytest_postgresql import factories _help_executable = "Path to PostgreSQL executable" _help_host = "Host at which PostgreSQL will accept connections" diff --git a/pytest_postgresql/retry.py b/pytest_postgresql/retry.py index 26a82053..d8337d58 100644 --- a/pytest_postgresql/retry.py +++ b/pytest_postgresql/retry.py @@ -2,8 +2,7 @@ from datetime import datetime, timedelta from time import sleep -from typing import Callable, TypeVar, Type - +from typing import Callable, Type, TypeVar T = TypeVar("T") @@ -11,8 +10,7 @@ def retry( func: Callable[[], T], timeout: int = 60, possible_exception: Type[Exception] = Exception ) -> T: - """ - Attempt to retry the function for timeout time. + """Attempt to retry the function for timeout time. Most often used for connecting to postgresql database as, especially on macos on github-actions, first few tries fails diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 85daa20c..00000000 --- a/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 100 -exclude = docs/*,build/*,venv/* diff --git a/tests/conftest.py b/tests/conftest.py index 5c2aea4e..d3274be1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,8 @@ """Tests main conftest file.""" import os -from pytest_postgresql.plugin import * # noqa: F403,F401 from pytest_postgresql import factories +from pytest_postgresql.plugin import * # noqa: F403,F401 pytest_plugins = ["pytester"] POSTGRESQL_VERSION = os.environ.get("POSTGRES", "13") diff --git a/tests/docker/test_nooproc_docker.py b/tests/docker/test_noproc_docker.py similarity index 95% rename from tests/docker/test_nooproc_docker.py rename to tests/docker/test_noproc_docker.py index 0a4d890d..0fbb246e 100644 --- a/tests/docker/test_nooproc_docker.py +++ b/tests/docker/test_noproc_docker.py @@ -1,3 +1,4 @@ +"""Noproc fixture tests.""" import pytest import pytest_postgresql.factories.client @@ -19,9 +20,7 @@ def test_postgres_docker_load(postgres_with_schema: connection) -> None: - """ - Check main postgres fixture - """ + """Check main postgres fixture.""" with postgres_with_schema.cursor() as cur: # Query for public.tokens since the eidastats changes postgres' search_path to ''. # The search path by default is public, but without it, diff --git a/tests/examples/test_postgres_options.py b/tests/examples/test_postgres_options.py index 4e6f9b1f..4d775157 100644 --- a/tests/examples/test_postgres_options.py +++ b/tests/examples/test_postgres_options.py @@ -1,9 +1,13 @@ -"""This is not called directly but is used in another test.""" +"""Options tests. + +Not called directly but is used in another test. +""" from typing import Any def test_postgres_options(postgresql: Any) -> None: + """Check if the max_connections is set as defined in mater test.""" cur = postgresql.cursor() cur.execute("SHOW max_connections") assert cur.fetchone() == ("16",) diff --git a/tests/test_executor.py b/tests/test_executor.py index 378742fa..0d04dac3 100644 --- a/tests/test_executor.py +++ b/tests/test_executor.py @@ -2,16 +2,15 @@ import sys from typing import Any -from pytest import FixtureRequest -from pkg_resources import parse_version - import pytest +from pkg_resources import parse_version from port_for import get_port +from pytest import FixtureRequest -from pytest_postgresql.executor import PostgreSQLExecutor, PostgreSQLUnsupported -from pytest_postgresql.factories import postgresql_proc, postgresql from pytest_postgresql.compat import connection, psycopg from pytest_postgresql.config import get_config +from pytest_postgresql.executor import PostgreSQLExecutor, PostgreSQLUnsupported +from pytest_postgresql.factories import postgresql, postgresql_proc from pytest_postgresql.retry import retry diff --git a/tests/test_janitor.py b/tests/test_janitor.py index 5b032dd7..694d3e20 100644 --- a/tests/test_janitor.py +++ b/tests/test_janitor.py @@ -1,7 +1,8 @@ """Database Janitor tests.""" import sys -from unittest.mock import patch, MagicMock from typing import Any +from unittest.mock import MagicMock, patch + import pytest from pkg_resources import parse_version @@ -45,8 +46,7 @@ def test_cursor_connects_with_password(connect_mock: MagicMock) -> None: ) @patch("pytest_postgresql.janitor.psycopg.connect") def test_janitor_populate(connect_mock: MagicMock, load_database: str) -> None: - """ - Test that the cursor requests the postgres database. + """Test that the cursor requests the postgres database. load_database tries to connect to database, which triggers mocks. """ diff --git a/tests/test_noopexecutor.py b/tests/test_noopexecutor.py index a0288c37..1de20342 100644 --- a/tests/test_noopexecutor.py +++ b/tests/test_noopexecutor.py @@ -1,13 +1,12 @@ """Test for NoopExecutor.""" -from pytest_postgresql.executor import PostgreSQLExecutor from pytest_postgresql.compat import psycopg +from pytest_postgresql.executor import PostgreSQLExecutor from pytest_postgresql.executor_noop import NoopExecutor from pytest_postgresql.retry import retry def test_noproc_version(postgresql_proc: PostgreSQLExecutor) -> None: - """ - Test the way postgresql version is being read. + """Test the way postgresql version is being read. Version behaves differently for postgresql >= 10 and differently for older ones """ diff --git a/tests/test_postgres_options_plugin.py b/tests/test_postgres_options_plugin.py index d766cec4..722955f5 100644 --- a/tests/test_postgres_options_plugin.py +++ b/tests/test_postgres_options_plugin.py @@ -3,14 +3,15 @@ import pytest from pytest import Pytester + import pytest_postgresql @pytest.fixture def pointed_pytester(pytester: Pytester) -> Pytester: + """Pre-configured pytester fixture.""" pytest_postgresql_path = Path(pytest_postgresql.__file__) root_path = pytest_postgresql_path.parent.parent - print(root_path) pytester.syspathinsert(root_path) pytester.makeconftest("from pytest_postgresql.plugin import *\n") return pytester diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 92e64005..abbadcf3 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -4,9 +4,9 @@ import pytest from psycopg.pq import ConnStatus +from pytest_postgresql.compat import connection from pytest_postgresql.executor import PostgreSQLExecutor from pytest_postgresql.retry import retry -from pytest_postgresql.compat import connection from tests.conftest import POSTGRESQL_VERSION MAKE_Q = "CREATE TABLE test (id serial PRIMARY KEY, num integer, data varchar);" @@ -68,12 +68,10 @@ def test_rand_postgres_port(postgresql2: connection) -> None: ) @pytest.mark.parametrize("_", range(2)) def test_postgres_terminate_connection(postgresql2: connection, _: int) -> None: - """ - Test that connections are terminated between tests. + """Test that connections are terminated between tests. And check that only one exists at a time. """ - with postgresql2.cursor() as cur: def check_if_one_connection() -> None: diff --git a/tests/test_template_database.py b/tests/test_template_database.py index f579dfe2..7d9cf5b3 100644 --- a/tests/test_template_database.py +++ b/tests/test_template_database.py @@ -1,8 +1,8 @@ """Template database tests.""" import pytest -from pytest_postgresql.factories import postgresql, postgresql_proc from pytest_postgresql.compat import connection +from pytest_postgresql.factories import postgresql, postgresql_proc from tests.loader import load_database postgresql_proc_with_template = postgresql_proc(