pytest-postgresql 9.0.0__tar.gz → 9.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/CHANGES.rst +18 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/PKG-INFO +14 -9
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/README.rst +12 -7
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pyproject.toml +4 -4
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pyproject.toml.orig +6 -4
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/__init__.py +1 -1
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/exceptions.py +12 -0
- pytest_postgresql-9.1.0/pytest_postgresql/factories/_pg.py +206 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/plugin.py +2 -1
- pytest_postgresql-9.0.0/pytest_postgresql/factories/_pg.py +0 -75
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/COPYING.lesser +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/_asyncio_compat.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/config.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/executors/__init__.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/executors/noop.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/executors/proc.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/factories/__init__.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/factories/client.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/factories/noprocess.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/factories/process.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/janitor.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/loader.py +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/py.typed +0 -0
- {pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/retry.py +0 -0
|
@@ -3,6 +3,24 @@ CHANGELOG
|
|
|
3
3
|
|
|
4
4
|
.. towncrier release notes start
|
|
5
5
|
|
|
6
|
+
pytest-postgresql 9.1.0 (2026-09-04)
|
|
7
|
+
====================================
|
|
8
|
+
|
|
9
|
+
Features
|
|
10
|
+
--------
|
|
11
|
+
|
|
12
|
+
- ``pg_ctl`` discovery now finds a Windows PostgreSQL install without ``--postgresql-exec``.
|
|
13
|
+
The default executable path is empty on Windows, and discovery probes
|
|
14
|
+
``%ProgramFiles%\PostgreSQL\*\bin\pg_ctl.exe`` (newest version first) and ``PATH`` after
|
|
15
|
+
``pg_config --bindir``. (`#1399 <https://github.com/dbfixtures/pytest-postgresql/issues/1399>`__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Miscellaneous
|
|
19
|
+
-------------
|
|
20
|
+
|
|
21
|
+
- Migrate tests to be based on `actions-reuse` new composite action `uv-pytest-coverage` (`#1424 <https://github.com/dbfixtures/pytest-postgresql/issues/1424>`__)
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
pytest-postgresql 9.0.0 (2026-08-28)
|
|
7
25
|
====================================
|
|
8
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-postgresql
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.1.0
|
|
4
4
|
Summary: Postgresql fixtures and fixture factories for Pytest.
|
|
5
5
|
Keywords: fixture,postgresql,pytest,tests
|
|
6
6
|
Author: Grzegorz Śliwiński
|
|
@@ -33,7 +33,7 @@ Requires-Dist: pytest-asyncio>=1.4 ; extra == 'async'
|
|
|
33
33
|
Requires-Python: >=3.10
|
|
34
34
|
Project-URL: Source, https://github.com/dbfixtures/pytest-postgresql
|
|
35
35
|
Project-URL: Bug Tracker, https://github.com/dbfixtures/pytest-postgresql/issues
|
|
36
|
-
Project-URL: Changelog, https://github.com/dbfixtures/pytest-postgresql/blob/v9.
|
|
36
|
+
Project-URL: Changelog, https://github.com/dbfixtures/pytest-postgresql/blob/v9.1.0/CHANGES.rst
|
|
37
37
|
Provides-Extra: async
|
|
38
38
|
Description-Content-Type: text/x-rst
|
|
39
39
|
|
|
@@ -382,7 +382,7 @@ You can define settings via fixture factory arguments, command line options, or
|
|
|
382
382
|
- n/a
|
|
383
383
|
- --postgresql-exec
|
|
384
384
|
- postgresql_exec
|
|
385
|
-
-
|
|
385
|
+
- discovered (see note)
|
|
386
386
|
* - host
|
|
387
387
|
- host
|
|
388
388
|
- host
|
|
@@ -479,13 +479,18 @@ You can define settings via fixture factory arguments, command line options, or
|
|
|
479
479
|
|
|
480
480
|
.. note::
|
|
481
481
|
|
|
482
|
-
If the ``executable`` factory argument is not provided, the plugin looks for ``pg_ctl``
|
|
483
|
-
|
|
484
|
-
``/usr/lib/postgresql/14/bin/pg_ctl`` by default), then in the directory reported by
|
|
485
|
-
``pg_config --bindir``.
|
|
482
|
+
If the ``executable`` factory argument is not provided, the plugin looks for ``pg_ctl`` in
|
|
483
|
+
this order:
|
|
486
484
|
|
|
487
|
-
|
|
488
|
-
|
|
485
|
+
1. the configured path (``--postgresql-exec`` / the ``postgresql_exec`` ini option;
|
|
486
|
+
on Unix this defaults to ``/usr/lib/postgresql/14/bin/pg_ctl``, on Windows there is no
|
|
487
|
+
default path),
|
|
488
|
+
2. the directory reported by ``pg_config --bindir``,
|
|
489
|
+
3. on Windows, ``%ProgramFiles%\PostgreSQL\*\bin\pg_ctl.exe`` (newest version first),
|
|
490
|
+
4. ``pg_ctl`` on ``PATH`` (via ``shutil.which``).
|
|
491
|
+
|
|
492
|
+
Only the ``executable`` factory argument is taken at face value; the other locations are
|
|
493
|
+
verified to exist before being used. If none of them is there, an ``ExecutableMissingException``
|
|
489
494
|
is raised listing the locations that were checked.
|
|
490
495
|
|
|
491
496
|
.. note::
|
|
@@ -343,7 +343,7 @@ You can define settings via fixture factory arguments, command line options, or
|
|
|
343
343
|
- n/a
|
|
344
344
|
- --postgresql-exec
|
|
345
345
|
- postgresql_exec
|
|
346
|
-
-
|
|
346
|
+
- discovered (see note)
|
|
347
347
|
* - host
|
|
348
348
|
- host
|
|
349
349
|
- host
|
|
@@ -440,13 +440,18 @@ You can define settings via fixture factory arguments, command line options, or
|
|
|
440
440
|
|
|
441
441
|
.. note::
|
|
442
442
|
|
|
443
|
-
If the ``executable`` factory argument is not provided, the plugin looks for ``pg_ctl``
|
|
444
|
-
|
|
445
|
-
``/usr/lib/postgresql/14/bin/pg_ctl`` by default), then in the directory reported by
|
|
446
|
-
``pg_config --bindir``.
|
|
443
|
+
If the ``executable`` factory argument is not provided, the plugin looks for ``pg_ctl`` in
|
|
444
|
+
this order:
|
|
447
445
|
|
|
448
|
-
|
|
449
|
-
|
|
446
|
+
1. the configured path (``--postgresql-exec`` / the ``postgresql_exec`` ini option;
|
|
447
|
+
on Unix this defaults to ``/usr/lib/postgresql/14/bin/pg_ctl``, on Windows there is no
|
|
448
|
+
default path),
|
|
449
|
+
2. the directory reported by ``pg_config --bindir``,
|
|
450
|
+
3. on Windows, ``%ProgramFiles%\PostgreSQL\*\bin\pg_ctl.exe`` (newest version first),
|
|
451
|
+
4. ``pg_ctl`` on ``PATH`` (via ``shutil.which``).
|
|
452
|
+
|
|
453
|
+
Only the ``executable`` factory argument is taken at face value; the other locations are
|
|
454
|
+
verified to exist before being used. If none of them is there, an ``ExecutableMissingException``
|
|
450
455
|
is raised listing the locations that were checked.
|
|
451
456
|
|
|
452
457
|
.. note::
|
|
@@ -4,7 +4,7 @@ requires = ["uv-build>=0.11,<0.13"]
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pytest-postgresql"
|
|
7
|
-
version = "9.
|
|
7
|
+
version = "9.1.0"
|
|
8
8
|
description = "Postgresql fixtures and fixture factories for Pytest."
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
keywords = [
|
|
@@ -55,7 +55,7 @@ async = [
|
|
|
55
55
|
[project.urls]
|
|
56
56
|
Source = "https://github.com/dbfixtures/pytest-postgresql"
|
|
57
57
|
"Bug Tracker" = "https://github.com/dbfixtures/pytest-postgresql/issues"
|
|
58
|
-
Changelog = "https://github.com/dbfixtures/pytest-postgresql/blob/v9.
|
|
58
|
+
Changelog = "https://github.com/dbfixtures/pytest-postgresql/blob/v9.1.0/CHANGES.rst"
|
|
59
59
|
|
|
60
60
|
[project.entry-points.pytest11]
|
|
61
61
|
pytest_postgresql = "pytest_postgresql.plugin"
|
|
@@ -74,10 +74,10 @@ dev = [
|
|
|
74
74
|
"pytest==9.1.1",
|
|
75
75
|
"pytest-asyncio==1.4.0",
|
|
76
76
|
"pytest-xdist==3.8.0",
|
|
77
|
-
"tbump==6.11.0",
|
|
78
77
|
"towncrier==25.8.0",
|
|
79
78
|
"types-aiofiles==25.1.0.20260518",
|
|
80
79
|
]
|
|
80
|
+
release = ["tbump==6.11.0"]
|
|
81
81
|
|
|
82
82
|
[tool.uv.build-backend]
|
|
83
83
|
module-name = "pytest_postgresql"
|
|
@@ -163,7 +163,7 @@ message_template = "Release {new_version}"
|
|
|
163
163
|
tag_template = "v{new_version}"
|
|
164
164
|
|
|
165
165
|
[tool.tbump.version]
|
|
166
|
-
current = "9.
|
|
166
|
+
current = "9.1.0"
|
|
167
167
|
regex = '''
|
|
168
168
|
(?P<major>\d+)
|
|
169
169
|
\.
|
|
@@ -4,7 +4,7 @@ requires = [ "uv-build>=0.11,<0.13" ]
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pytest-postgresql"
|
|
7
|
-
version = "9.
|
|
7
|
+
version = "9.1.0"
|
|
8
8
|
description = "Postgresql fixtures and fixture factories for Pytest."
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
keywords = [ "fixture", "postgresql", "pytest", "tests" ]
|
|
@@ -41,7 +41,7 @@ async = [ "aiofiles>=23.0", "pytest-asyncio>=1.4" ]
|
|
|
41
41
|
[project.urls]
|
|
42
42
|
Source = "https://github.com/dbfixtures/pytest-postgresql"
|
|
43
43
|
"Bug Tracker" = "https://github.com/dbfixtures/pytest-postgresql/issues"
|
|
44
|
-
Changelog = "https://github.com/dbfixtures/pytest-postgresql/blob/v9.
|
|
44
|
+
Changelog = "https://github.com/dbfixtures/pytest-postgresql/blob/v9.1.0/CHANGES.rst"
|
|
45
45
|
|
|
46
46
|
[project.entry-points.pytest11]
|
|
47
47
|
pytest_postgresql = "pytest_postgresql.plugin"
|
|
@@ -60,10 +60,12 @@ dev = [
|
|
|
60
60
|
"pytest==9.1.1",
|
|
61
61
|
"pytest-asyncio==1.4.0",
|
|
62
62
|
"pytest-xdist==3.8.0",
|
|
63
|
-
"tbump==6.11.0",
|
|
64
63
|
"towncrier==25.8.0",
|
|
65
64
|
"types-aiofiles==25.1.0.20260518",
|
|
66
65
|
]
|
|
66
|
+
release = [
|
|
67
|
+
"tbump==6.11.0",
|
|
68
|
+
]
|
|
67
69
|
|
|
68
70
|
[tool.uv.build-backend]
|
|
69
71
|
module-name = "pytest_postgresql"
|
|
@@ -144,7 +146,7 @@ message_template = "Release {new_version}"
|
|
|
144
146
|
tag_template = "v{new_version}"
|
|
145
147
|
|
|
146
148
|
[tool.tbump.version]
|
|
147
|
-
current = "9.
|
|
149
|
+
current = "9.1.0"
|
|
148
150
|
regex = '''
|
|
149
151
|
(?P<major>\d+)
|
|
150
152
|
\.
|
|
@@ -50,6 +50,18 @@ class ExecutableMissingException(FileNotFoundError):
|
|
|
50
50
|
checked,
|
|
51
51
|
)
|
|
52
52
|
|
|
53
|
+
@classmethod
|
|
54
|
+
def discovery_failed(cls, causes: Iterable[str], checked: Iterable[str]) -> "ExecutableMissingException":
|
|
55
|
+
"""None of the discovery strategies found a runnable pg_ctl.
|
|
56
|
+
|
|
57
|
+
:param causes: why each strategy came up empty, joined into one explanation
|
|
58
|
+
:param checked: every location that was probed
|
|
59
|
+
"""
|
|
60
|
+
cause = " ".join(causes)
|
|
61
|
+
if not cause:
|
|
62
|
+
cause = "No pg_ctl was found in any of the usual locations."
|
|
63
|
+
return cls._no_pg_ctl(cause, checked)
|
|
64
|
+
|
|
53
65
|
|
|
54
66
|
class PostgreSQLUnsupported(Exception):
|
|
55
67
|
"""Exception raised when unsupported postgresql would be detected."""
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Internal module for functions handling pg_ctl discovery."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
import platform
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from pytest_postgresql.config import PostgreSQLConfig
|
|
11
|
+
from pytest_postgresql.exceptions import ExecutableMissingException
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
PG_CTL_NAMES = ("pg_ctl.exe", "pg_ctl") if platform.system() == "Windows" else ("pg_ctl",)
|
|
16
|
+
"""Names to look for when probing the filesystem for pg_ctl.
|
|
17
|
+
|
|
18
|
+
os.path.isfile matches the literal name, so finding the binary on Windows means asking
|
|
19
|
+
for pg_ctl.exe. Launching it is more forgiving: Windows appends .exe to an extensionless
|
|
20
|
+
program name, which is why the old code could run a path it never checked.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
PG_CONFIG_TIMEOUT = 60
|
|
24
|
+
"""Seconds to wait for pg_config, so a hung binary cannot stall fixture setup.
|
|
25
|
+
|
|
26
|
+
Matches PostgreSQLExecutor's default subprocess timeout.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
_WINDOWS_PROGRAM_FILES_FALLBACK = r"C:\Program Files"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _pg_bindir() -> str:
|
|
33
|
+
"""Ask pg_config where PostgreSQL keeps its binaries.
|
|
34
|
+
|
|
35
|
+
pg_config comes from the client development package, which on most distributions
|
|
36
|
+
can be installed without the server, so its answer is a hint rather than an answer.
|
|
37
|
+
|
|
38
|
+
:raises OSError: pg_config is missing or not executable
|
|
39
|
+
:raises subprocess.SubprocessError: pg_config failed or hung.
|
|
40
|
+
TimeoutExpired is a SubprocessError, so it needs no branch of its own.
|
|
41
|
+
"""
|
|
42
|
+
try:
|
|
43
|
+
bindir = subprocess.check_output(
|
|
44
|
+
["pg_config", "--bindir"], universal_newlines=True, timeout=PG_CONFIG_TIMEOUT
|
|
45
|
+
).strip()
|
|
46
|
+
except (OSError, subprocess.SubprocessError) as ex:
|
|
47
|
+
logger.debug("Could not read the binaries directory from pg_config: %s", ex)
|
|
48
|
+
raise
|
|
49
|
+
logger.debug("pg_config --bindir reported %s", bindir)
|
|
50
|
+
return bindir
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _is_executable(path: str) -> bool:
|
|
54
|
+
"""Whether path is a file this user can actually run.
|
|
55
|
+
|
|
56
|
+
isfile is needed alongside the access check because X_OK on a directory only means
|
|
57
|
+
it can be traversed. On Windows os.access ignores X_OK, so this is an existence test.
|
|
58
|
+
"""
|
|
59
|
+
return os.path.isfile(path) and os.access(path, os.X_OK)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _windows_postgresql_root() -> Path:
|
|
63
|
+
"""Directory under which the Windows installer places versioned PostgreSQL copies."""
|
|
64
|
+
program_files = os.environ.get("ProgramFiles", _WINDOWS_PROGRAM_FILES_FALLBACK)
|
|
65
|
+
return Path(program_files) / "PostgreSQL"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _windows_version_sort_key(name: str) -> tuple[int, tuple[int, ...] | str]:
|
|
69
|
+
"""Sort key for Windows PostgreSQL version directory names, newest first when reversed.
|
|
70
|
+
|
|
71
|
+
Numeric versions (``16``, ``16.4``) rank above non-numeric names so a real install
|
|
72
|
+
wins over stray folders; non-numeric names fall back to lexicographic comparison.
|
|
73
|
+
"""
|
|
74
|
+
parts = name.split(".")
|
|
75
|
+
try:
|
|
76
|
+
numbers = tuple(int(part) for part in parts)
|
|
77
|
+
except ValueError:
|
|
78
|
+
return (0, name)
|
|
79
|
+
return (1, numbers)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _windows_program_files_pg_ctls() -> list[str]:
|
|
83
|
+
"""pg_ctl paths under Program Files/PostgreSQL/*/bin, newest version first."""
|
|
84
|
+
root = _windows_postgresql_root()
|
|
85
|
+
if not root.is_dir():
|
|
86
|
+
logger.debug("Windows PostgreSQL directory does not exist: %s", root)
|
|
87
|
+
return []
|
|
88
|
+
found: list[tuple[str, str]] = []
|
|
89
|
+
try:
|
|
90
|
+
version_dirs = [entry for entry in root.iterdir() if entry.is_dir()]
|
|
91
|
+
except OSError as ex:
|
|
92
|
+
logger.debug("Could not scan %s: %s", root, ex)
|
|
93
|
+
return []
|
|
94
|
+
for version_dir in version_dirs:
|
|
95
|
+
bindir = version_dir / "bin"
|
|
96
|
+
for name in PG_CTL_NAMES:
|
|
97
|
+
candidate = bindir / name
|
|
98
|
+
if candidate.is_file():
|
|
99
|
+
found.append((version_dir.name, str(candidate)))
|
|
100
|
+
found.sort(key=lambda item: _windows_version_sort_key(item[0]), reverse=True)
|
|
101
|
+
paths = [path for _, path in found]
|
|
102
|
+
logger.debug("Windows Program Files pg_ctl candidates (newest first): %s", paths)
|
|
103
|
+
return paths
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _which_pg_ctl() -> str | None:
|
|
107
|
+
"""Return pg_ctl from PATH, if it is a file this user can run."""
|
|
108
|
+
for name in PG_CTL_NAMES:
|
|
109
|
+
found = shutil.which(name)
|
|
110
|
+
if found is None:
|
|
111
|
+
logger.debug("which(%s) found nothing", name)
|
|
112
|
+
continue
|
|
113
|
+
logger.debug("which(%s) found %s", name, found)
|
|
114
|
+
if _is_executable(found):
|
|
115
|
+
return found
|
|
116
|
+
return None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _remember(checked: list[str], candidate: str) -> None:
|
|
120
|
+
"""Append candidate to the probed-locations list unless it is already there."""
|
|
121
|
+
if candidate not in checked:
|
|
122
|
+
checked.append(candidate)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _from_config_exec(config: PostgreSQLConfig, checked: list[str]) -> str | None:
|
|
126
|
+
"""Use postgresql_exec when it names a real executable."""
|
|
127
|
+
postgresql_ctl = config.exec
|
|
128
|
+
if not postgresql_ctl:
|
|
129
|
+
logger.debug("No postgresql_exec configured; skipping that probe")
|
|
130
|
+
return None
|
|
131
|
+
logger.debug("Checking configured postgresql_exec: %s", postgresql_ctl)
|
|
132
|
+
if _is_executable(postgresql_ctl):
|
|
133
|
+
logger.debug("Using configured postgresql_exec: %s", postgresql_ctl)
|
|
134
|
+
return postgresql_ctl
|
|
135
|
+
_remember(checked, postgresql_ctl)
|
|
136
|
+
return None
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _from_pg_config(checked: list[str], causes: list[str]) -> str | None:
|
|
140
|
+
"""Use pg_ctl next to the binaries directory pg_config reports, if any."""
|
|
141
|
+
try:
|
|
142
|
+
bindir = _pg_bindir()
|
|
143
|
+
except (OSError, subprocess.SubprocessError) as ex:
|
|
144
|
+
reason = f"{type(ex).__name__}: {ex}"
|
|
145
|
+
logger.debug("pg_config unusable: %s", reason)
|
|
146
|
+
causes.append(
|
|
147
|
+
f"pg_config could not be run either ({reason}), so it could not be used to locate the PostgreSQL binaries."
|
|
148
|
+
)
|
|
149
|
+
return None
|
|
150
|
+
for name in PG_CTL_NAMES:
|
|
151
|
+
candidate = os.path.join(bindir, name)
|
|
152
|
+
_remember(checked, candidate)
|
|
153
|
+
if _is_executable(candidate):
|
|
154
|
+
logger.debug("Using pg_ctl from pg_config bindir: %s", candidate)
|
|
155
|
+
return candidate
|
|
156
|
+
causes.append(
|
|
157
|
+
f"pg_config reports PostgreSQL binaries live in {bindir}, but there's no pg_ctl there. "
|
|
158
|
+
f"That usually means only the PostgreSQL client libraries are installed "
|
|
159
|
+
f"(Debian/Ubuntu's libpq-dev, for example), without the matching server package."
|
|
160
|
+
)
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _from_windows_program_files(checked: list[str]) -> str | None:
|
|
165
|
+
"""Use the newest Windows installer copy of pg_ctl, if this is Windows."""
|
|
166
|
+
if platform.system() != "Windows":
|
|
167
|
+
return None
|
|
168
|
+
logger.debug("Probing %s for pg_ctl", _windows_postgresql_root())
|
|
169
|
+
for candidate in _windows_program_files_pg_ctls():
|
|
170
|
+
_remember(checked, candidate)
|
|
171
|
+
if _is_executable(candidate):
|
|
172
|
+
logger.debug("Using pg_ctl from Program Files: %s", candidate)
|
|
173
|
+
return candidate
|
|
174
|
+
return None
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _from_path(checked: list[str]) -> str | None:
|
|
178
|
+
"""Use pg_ctl from PATH."""
|
|
179
|
+
found = _which_pg_ctl()
|
|
180
|
+
if found is None:
|
|
181
|
+
logger.debug("shutil.which did not find pg_ctl on PATH")
|
|
182
|
+
return None
|
|
183
|
+
_remember(checked, found)
|
|
184
|
+
if _is_executable(found):
|
|
185
|
+
logger.debug("Using pg_ctl from PATH: %s", found)
|
|
186
|
+
return found
|
|
187
|
+
return None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def _pg_exe(executable: str | None, config: PostgreSQLConfig) -> str:
|
|
191
|
+
"""If executable is set, use it. Otherwise best effort to find the executable."""
|
|
192
|
+
if executable is not None:
|
|
193
|
+
logger.debug("Using factory executable: %s", executable)
|
|
194
|
+
return executable
|
|
195
|
+
checked: list[str] = []
|
|
196
|
+
causes: list[str] = []
|
|
197
|
+
found = (
|
|
198
|
+
_from_config_exec(config, checked)
|
|
199
|
+
or _from_pg_config(checked, causes)
|
|
200
|
+
or _from_windows_program_files(checked)
|
|
201
|
+
or _from_path(checked)
|
|
202
|
+
)
|
|
203
|
+
if found is not None:
|
|
204
|
+
return found
|
|
205
|
+
logger.debug("pg_ctl discovery failed; checked %s", checked)
|
|
206
|
+
raise ExecutableMissingException.discovery_failed(causes, checked)
|
|
@@ -37,6 +37,7 @@ except ImportError:
|
|
|
37
37
|
pytest_asyncio = None # type: ignore[assignment]
|
|
38
38
|
|
|
39
39
|
_help_executable = "Path to PostgreSQL executable"
|
|
40
|
+
_DEFAULT_POSTGRESQL_EXEC = "" if platform.system() == "Windows" else "/usr/lib/postgresql/14/bin/pg_ctl"
|
|
40
41
|
_help_host = "Host at which PostgreSQL will accept connections"
|
|
41
42
|
_help_port = "Port at which PostgreSQL will accept connections"
|
|
42
43
|
_help_port_search_count = "Number of times, pytest-postgresql will search for free port"
|
|
@@ -144,7 +145,7 @@ if _is_windows():
|
|
|
144
145
|
|
|
145
146
|
def pytest_addoption(parser: Parser) -> None:
|
|
146
147
|
"""Configure options for pytest-postgresql."""
|
|
147
|
-
parser.addini(name="postgresql_exec", help=_help_executable, default=
|
|
148
|
+
parser.addini(name="postgresql_exec", help=_help_executable, default=_DEFAULT_POSTGRESQL_EXEC)
|
|
148
149
|
|
|
149
150
|
parser.addini(name="postgresql_host", help=_help_host, default="127.0.0.1")
|
|
150
151
|
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"""Internal module for functions handling pg_ctl discovery."""
|
|
2
|
-
|
|
3
|
-
import logging
|
|
4
|
-
import os
|
|
5
|
-
import platform
|
|
6
|
-
import subprocess
|
|
7
|
-
from typing import Iterable
|
|
8
|
-
|
|
9
|
-
from pytest_postgresql.config import PostgreSQLConfig
|
|
10
|
-
from pytest_postgresql.exceptions import ExecutableMissingException
|
|
11
|
-
|
|
12
|
-
logger = logging.getLogger(__name__)
|
|
13
|
-
|
|
14
|
-
PG_CTL_NAMES = ("pg_ctl.exe", "pg_ctl") if platform.system() == "Windows" else ("pg_ctl",)
|
|
15
|
-
"""Names to look for when probing the filesystem for pg_ctl.
|
|
16
|
-
|
|
17
|
-
os.path.isfile matches the literal name, so finding the binary on Windows means asking
|
|
18
|
-
for pg_ctl.exe. Launching it is more forgiving: Windows appends .exe to an extensionless
|
|
19
|
-
program name, which is why the old code could run a path it never checked.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
PG_CONFIG_TIMEOUT = 60
|
|
23
|
-
"""Seconds to wait for pg_config, so a hung binary cannot stall fixture setup.
|
|
24
|
-
|
|
25
|
-
Matches PostgreSQLExecutor's default subprocess timeout.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def _pg_bindir(checked: Iterable[str]) -> str:
|
|
30
|
-
"""Ask pg_config where PostgreSQL keeps its binaries.
|
|
31
|
-
|
|
32
|
-
pg_config comes from the client development package, which on most distributions
|
|
33
|
-
can be installed without the server, so its answer is a hint rather than an answer.
|
|
34
|
-
|
|
35
|
-
:param checked: locations probed so far, to name in the error if pg_config can't be run
|
|
36
|
-
:raises ExecutableMissingException: pg_config is missing, unusable, hanging or failing.
|
|
37
|
-
TimeoutExpired is a SubprocessError, so it needs no branch of its own.
|
|
38
|
-
"""
|
|
39
|
-
try:
|
|
40
|
-
return subprocess.check_output(
|
|
41
|
-
["pg_config", "--bindir"], universal_newlines=True, timeout=PG_CONFIG_TIMEOUT
|
|
42
|
-
).strip()
|
|
43
|
-
except (OSError, subprocess.SubprocessError) as ex:
|
|
44
|
-
logger.debug("Could not read the binaries directory from pg_config: %s", ex)
|
|
45
|
-
raise ExecutableMissingException.pg_config_unusable(f"{type(ex).__name__}: {ex}", checked) from ex
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _is_executable(path: str) -> bool:
|
|
49
|
-
"""Whether path is a file this user can actually run.
|
|
50
|
-
|
|
51
|
-
isfile is needed alongside the access check because X_OK on a directory only means
|
|
52
|
-
it can be traversed. On Windows os.access ignores X_OK, so this is an existence test.
|
|
53
|
-
"""
|
|
54
|
-
return os.path.isfile(path) and os.access(path, os.X_OK)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def _pg_exe(executable: str | None, config: PostgreSQLConfig) -> str:
|
|
58
|
-
"""If executable is set, use it. Otherwise best effort to find the executable."""
|
|
59
|
-
# an explicitly passed executable is taken at face value, it's not ours to second-guess
|
|
60
|
-
if executable is not None:
|
|
61
|
-
return executable
|
|
62
|
-
postgresql_ctl = config.exec
|
|
63
|
-
# check if that executable exists, as it's not on systems' PATH
|
|
64
|
-
if _is_executable(postgresql_ctl):
|
|
65
|
-
return postgresql_ctl
|
|
66
|
-
checked = [postgresql_ctl]
|
|
67
|
-
bindir = _pg_bindir(checked)
|
|
68
|
-
for name in PG_CTL_NAMES:
|
|
69
|
-
candidate = os.path.join(bindir, name)
|
|
70
|
-
if candidate in checked:
|
|
71
|
-
continue
|
|
72
|
-
checked.append(candidate)
|
|
73
|
-
if _is_executable(candidate):
|
|
74
|
-
return candidate
|
|
75
|
-
raise ExecutableMissingException.not_in_bindir(bindir, checked)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_postgresql-9.0.0 → pytest_postgresql-9.1.0}/pytest_postgresql/factories/noprocess.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|