Skip to content

Commit

Permalink
Replace tmpdir with tmo_path fixtures - closes #533
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed Feb 14, 2022
1 parent 7d4284c commit 680e4d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGES.rst
@@ -1,6 +1,18 @@
CHANGELOG
=========

unreleased
----------

These changes were cherry-picked from v4

Features
++++++++

- Import FixtureRequest from pytest, not private _pytest.
Require at least pytest 6.2
- Replace tmpdir_factory with tmp_path_factory

3.1.2
----------

Expand Down
15 changes: 8 additions & 7 deletions src/pytest_postgresql/factories/process.py
Expand Up @@ -23,8 +23,7 @@
from typing import Union, Callable, List, Iterator, Optional, Tuple, Set

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
9 changes: 5 additions & 4 deletions tests/test_executor.py
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

0 comments on commit 680e4d4

Please sign in to comment.