Skip to content

Commit

Permalink
Merge pull request #562 from ClearcodeHQ/tmp
Browse files Browse the repository at this point in the history
Replace tmpdir with tmo_path fixtures - closes #533
  • Loading branch information
fizyk committed Feb 14, 2022
2 parents fef18a9 + f5ef769 commit 67d8a4a
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests-macos.yml
Expand Up @@ -22,8 +22,8 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: [3.7, 3.8, 3.9, pypy-3.7-v7.3.3]
postgres-version: [11, 12, 13]
python-version: [3.8, 3.9, "3.10", pypy-3.8-v7.3.7]
postgres-version: [13]
env:
OS: macos-latest
PYTHON: ${{ matrix.python-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: [3.7, 3.8, 3.9, pypy-3.7-v7.3.3]
postgres-version: [9.6, 10, 11, 12, 13]
python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.8-v7.3.7]
postgres-version: [12, 13, 14]
env:
OS: ubuntu-latest
PYTHON: ${{ matrix.python-version }}
Expand Down
13 changes: 13 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,19 @@
CHANGELOG
=========

unreleased
----------

Cherry picked from v4.x

Misc
++++

- Import FixtureRequest from pytest, not private _pytest.
Require at least pytest 6.2
- Replace tmpdir_factory with tmp_path_factory
- Add Postgresql 14 to the CI

3.1.2
----------

Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Expand Up @@ -2,7 +2,7 @@
pip>=9 # minimum installation requirements
setuptools>=21 # minimum installation requirements
coverage==6.0.2 # pytest-cov
pytest==6.2.5
pytest==7.0.1
pytest-cov==3.0.0
pytest-xdist==2.4.0
port-for==0.6.1
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -34,7 +34,7 @@ packages = find:
package_dir =
=src
install_requires =
pytest>=3.0.0
pytest>=6.2.0
port-for
mirakuru>=2.3.0

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_postgresql/config.py
@@ -1,4 +1,4 @@
from _pytest.fixtures import FixtureRequest
from pytest import FixtureRequest


def get_config(request: FixtureRequest) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_postgresql/factories/client.py
Expand Up @@ -19,7 +19,7 @@
from typing import List, Optional, Callable, Union

import pytest
from _pytest.fixtures import FixtureRequest
from pytest import FixtureRequest

from pytest_postgresql.compat import connection, check_for_psycopg2, psycopg2
from pytest_postgresql.config import get_config
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_postgresql/factories/noprocess.py
Expand Up @@ -19,7 +19,7 @@
from typing import Union, Callable, List, Iterator, Optional

import pytest
from _pytest.fixtures import FixtureRequest
from pytest import FixtureRequest

from pytest_postgresql.config import get_config
from pytest_postgresql.executor_noop import NoopExecutor
Expand Down
17 changes: 9 additions & 8 deletions src/pytest_postgresql/factories/process.py
Expand Up @@ -19,12 +19,11 @@
import os.path
import platform
import subprocess
from _warnings import warn
from typing import Union, Callable, List, Iterator, Optional, Tuple, Set
from warnings import warn

import pytest
from _pytest.fixtures import FixtureRequest
from _pytest.tmpdir import TempdirFactory
from pytest import FixtureRequest, TempPathFactory
from port_for import get_port

from pytest_postgresql.config import get_config
Expand Down Expand Up @@ -57,7 +56,7 @@ def postgresql_proc(
logs_prefix: str = "",
postgres_options: Optional[str] = None,
load: Optional[List[Union[Callable, str]]] = None,
) -> Callable[[FixtureRequest, TempdirFactory], Iterator[PostgreSQLExecutor]]:
) -> Callable[[FixtureRequest, TempPathFactory], Iterator[PostgreSQLExecutor]]:
"""
Postgresql process factory.
Expand All @@ -84,12 +83,13 @@ def postgresql_proc(

@pytest.fixture(scope="session")
def postgresql_proc_fixture(
request: FixtureRequest, tmpdir_factory: TempdirFactory
request: FixtureRequest, tmp_path_factory: TempPathFactory
) -> Iterator[PostgreSQLExecutor]:
"""
Process fixture for PostgreSQL.
:param request: fixture request object
:param tmp_path_factory: temporary path object (fixture)
:returns: tcp executor
"""
config = get_config(request)
Expand All @@ -106,7 +106,7 @@ def postgresql_proc_fixture(
).strip()
postgresql_ctl = os.path.join(pg_bindir, "pg_ctl")

tmpdir = tmpdir_factory.mktemp(f"pytest-postgresql-{request.fixturename}")
tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.fixturename}")

if logfile_prefix:
warn(
Expand All @@ -118,8 +118,9 @@ def postgresql_proc_fixture(

pg_port = get_port(port) or get_port(config["port"])
assert pg_port is not None
datadir = tmpdir.mkdir(f"data-{pg_port}")
logfile_path = tmpdir.join(f"{logfile_prefix}postgresql.{pg_port}.log")
datadir = tmpdir / f"data-{pg_port}"
datadir.mkdir()
logfile_path = tmpdir / f"{logfile_prefix}postgresql.{pg_port}.log"

if platform.system() == "FreeBSD":
with (datadir / "pg_hba.conf").open(mode="a") as conf_file:
Expand Down
11 changes: 6 additions & 5 deletions tests/test_executor.py
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Any

from _pytest.fixtures import FixtureRequest
from pytest import FixtureRequest
from pkg_resources import parse_version

import psycopg2
Expand Down Expand Up @@ -51,17 +51,18 @@ def test_unsupported_version(request: FixtureRequest) -> None:
def test_executor_init_with_password(
request: FixtureRequest,
monkeypatch: pytest.MonkeyPatch,
tmpdir_factory: pytest.TempdirFactory,
tmp_path_factory: pytest.TempPathFactory,
locale: str,
) -> None:
"""Test whether the executor initializes properly."""
config = get_config(request)
monkeypatch.setenv("LC_ALL", locale)
port = get_port(config["port"])
assert port is not None
tmpdir = tmpdir_factory.mktemp(f"pytest-postgresql-{request.node.name}")
datadir = tmpdir.mkdir(f"data-{port}")
logfile_path = tmpdir.join(f"postgresql.{port}.log")
tmpdir = tmp_path_factory.mktemp(f"pytest-postgresql-{request.node.name}")
datadir = tmpdir / f"data-{port}"
datadir.mkdir()
logfile_path = tmpdir / f"postgresql.{port}.log"
executor = PostgreSQLExecutor(
executable=config["exec"],
host=config["host"],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_postgres_options_plugin.py
@@ -1,6 +1,6 @@
"""Test behavior of postgres_options passed in different ways."""

from _pytest.pytester import Pytester
from pytest import Pytester


def test_postgres_options_config_in_cli(pytester: Pytester) -> None:
Expand Down

0 comments on commit 67d8a4a

Please sign in to comment.