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 Dec 22, 2021
1 parent 4e19c3e commit 2ae96bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions CHANGES.rst
Expand Up @@ -4,11 +4,12 @@ CHANGELOG
unreleased
----------

Misc
++++
Features
++++++++

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

4.0.0
----------
Expand Down
14 changes: 8 additions & 6 deletions src/pytest_postgresql/factories/process.py
Expand Up @@ -23,7 +23,7 @@
from warnings import warn

import pytest
from pytest import FixtureRequest, TempdirFactory
from pytest import FixtureRequest, TempPathFactory
from port_for import get_port

from pytest_postgresql.config import get_config
Expand Down Expand Up @@ -56,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 @@ -83,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 @@ -105,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 @@ -117,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 2ae96bc

Please sign in to comment.