Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions newsfragments/+3f45d2d2.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue, where defining load paths in ini/toml configuration would fail
due to pytest's LocalPath not having an endswith method.
5 changes: 4 additions & 1 deletion pytest_postgresql/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
from typing import Any, List, Optional, TypedDict, Union

from _pytest._py.path import LocalPath
from pytest import FixtureRequest


Expand Down Expand Up @@ -50,10 +51,12 @@ def get_postgresql_option(option: str) -> Any:
)


def detect_paths(load_paths: List[str]) -> List[Union[Path, str]]:
def detect_paths(load_paths: List[Union[LocalPath, str]]) -> List[Union[Path, str]]:
"""Convert path to sql files to Path instances."""
converted_load_paths: List[Union[Path, str]] = []
for path in load_paths:
if isinstance(path, LocalPath):
path = str(path)
if path.endswith(".sql"):
converted_load_paths.append(Path(path))
else:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Config tests."""

from pathlib import Path
from typing import Union

import pytest
from _pytest._py.path import LocalPath

from pytest_postgresql.config import detect_paths


@pytest.mark.parametrize(
"path, want",
(
("test.sql", Path("test.sql")),
("load.function", "load.function"),
(LocalPath("test.sql"), Path("test.sql").absolute()), # type: ignore[no-untyped-call]
),
)
def test_detect_paths(path: Union[str, LocalPath], want: Union[Path, str]) -> None:
"""Check the correctness of detect_paths function."""
assert detect_paths([path]) == [want]
9 changes: 9 additions & 0 deletions tests/test_postgres_options_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ def test_postgres_loader_in_cli(pointed_pytester: Pytester) -> None:
ret.assert_outcomes(passed=1)


def test_postgres_loader_in_ini(pointed_pytester: Pytester) -> None:
"""Check that pytest.ini arguments are honored for load."""
pointed_pytester.copy_example("test_load.py")
test_sql_path = pointed_pytester.copy_example("test.sql")
pointed_pytester.makefile(".ini", pytest=f"[pytest]\npostgresql_load = {test_sql_path}\n")
ret = pointed_pytester.runpytest("test_load.py")
ret.assert_outcomes(passed=1)


postgresql_proc_to_override = postgresql_proc()


Expand Down
Loading