You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docstrings generation was requested by @fizyk.
* #1241 (comment)
The following files were modified:
* `pytest_postgresql/config.py`
* `pytest_postgresql/factories/client.py`
* `pytest_postgresql/factories/noprocess.py`
* `pytest_postgresql/factories/process.py`
* `tests/test_executor.py`
Create a PostgreSQLConfig populated from pytest configuration options.
33
+
34
+
Reads pytest options and INI values prefixed with "postgresql_" to populate a PostgreSQLConfig dataclass. The "load" option is normalized to Paths or strings and "port_search_count" is converted to an int.
35
+
36
+
Parameters:
37
+
request (FixtureRequest): pytest fixture request used to read config options and INI values.
38
+
39
+
Returns:
40
+
PostgreSQLConfig: Configuration populated from the pytest settings.
41
+
"""
32
42
33
43
defget_postgresql_option(option: str) ->Any:
44
+
"""
45
+
Retrieve a PostgreSQL-related pytest configuration value.
46
+
47
+
Parameters:
48
+
option (str): The suffix of the configuration name (without the "postgresql_" prefix).
49
+
50
+
Returns:
51
+
The value of the pytest configuration option named "postgresql_<option>", or `None` if not set.
"""Convert path to sql files to Path instances."""
78
+
"""
79
+
Normalize a sequence of load paths so SQL file paths are Path objects and other entries are preserved.
80
+
81
+
Parameters:
82
+
load_paths (list[LocalPath | str]): Iterable of paths to normalize; entries may be pytest LocalPath objects or strings.
83
+
84
+
Returns:
85
+
list[Path | str]: A new list where entries that refer to files ending with ".sql" are returned as pathlib.Path objects and all other entries are returned unchanged (strings).
:returns: function which makes a connection to postgresql
38
+
"""
39
+
Create a pytest fixture factory that yields a PostgreSQL connection.
40
+
41
+
Parameters:
42
+
process_fixture_name (str): Name of the pytest fixture that provides the database process executor (used to obtain host, port, user, password, template DB name, and server version).
43
+
dbname (str | None): Database name to connect to; if None, use the executor's database name.
44
+
isolation_level (psycopg.IsolationLevel | None): Optional transaction isolation level to configure the janitor; if None, use the server default.
45
+
46
+
Returns:
47
+
Callable[[FixtureRequest], Iterator[psycopg.Connection]]: A pytest fixture factory function which, when used in a test, yields an open psycopg Connection to the specified database and ensures database janitor lifecycle management around the connection.
Provide a pytest fixture that yields a psycopg Connection to the test PostgreSQL database.
54
+
55
+
The fixture resolves the process executor and global config from the given request, prepares or drops the test database as configured, and manages the database janitor and connection lifecycle so the connection is open for the duration of the consuming test.
56
+
57
+
Parameters:
58
+
request (FixtureRequest): Pytest fixture request used to obtain the process fixture and test configuration.
59
+
60
+
Returns:
61
+
Connection: A psycopg Connection connected to the selected test database; the connection is closed after the fixture completes.
:param load: List of functions used to initialize database's template.
58
-
:returns: function which makes a postgresql process
49
+
"""
50
+
Create a pytest session-scoped fixture that provides a NoopExecutor connected to an existing PostgreSQL server.
51
+
52
+
The returned fixture resolves connection parameters from the explicit arguments or from the test configuration, applies xdist worker-specific adjustment to the database name, and uses a DatabaseJanitor to optionally drop the test database and load initialization elements into the template before yielding the configured NoopExecutor.
53
+
54
+
Parameters:
55
+
host (str | None): Hostname to connect to; if None, taken from test configuration.
56
+
port (str | int | None): Port to connect to; if None, taken from configuration or defaults to 5432.
57
+
user (str | None): Username to authenticate as; if None, taken from configuration.
58
+
password (str | None): Password to authenticate with; if None, taken from configuration.
59
+
dbname (str | None): Base database name; if None, taken from configuration. The name is adjusted when pytest-xdist is in use.
60
+
options (str): Additional connection options; if empty, taken from configuration.
61
+
load (list[Callable | str | Path] | None): Sequence of initialization elements (callables or filesystem paths) to load into the database template; if None, taken from configuration.
62
+
63
+
Returns:
64
+
Callable[[FixtureRequest], Iterator[NoopExecutor]]: A pytest fixture function which yields a configured NoopExecutor instance.
Provide a pytest fixture that yields a NoopExecutor configured for an existing PostgreSQL server.
71
+
72
+
The fixture resolves connection parameters from the fixture request and the factory's closure values, applies xdist-aware database name transformation, and uses a DatabaseJanitor context to optionally drop the test database (if configured) and load initialization elements into the database template before yielding the executor.
73
+
74
+
Parameters:
75
+
request (FixtureRequest): Pytest fixture request used to obtain configuration.
76
+
77
+
Returns:
78
+
noop_exec (NoopExecutor): Executor-like object configured with the resolved host, port, user, password, dbname, and options.
:param unixsocketdir: directory to create postgresql's unixsockets
102
-
:param postgres_options: Postgres executable options for use by pg_ctl
103
-
:param load: List of functions used to initialize database's template.
104
-
:returns: function which makes a postgresql process
111
+
"""
112
+
Create a pytest fixture factory that starts a temporary PostgreSQL server process for tests.
113
+
114
+
This factory returns a session-scoped fixture which allocates a port, initializes a data directory, starts PostgreSQL, runs initial load steps into the template database, and yields a PostgreSQLExecutor for test use. The fixture ensures the server is stopped and cleaned up when tests finish.
115
+
116
+
Parameters:
117
+
executable (str | None): Path to the PostgreSQL control executable (pg_ctl). If None, the configured executable or pg_config discovery will be used.
118
+
port (PortType | None | int): Port selection specification. Accepts:
119
+
- an exact port (e.g. 8000 or "8000"),
120
+
- None to select any available port,
121
+
- -1 to use the command-line or pytest.ini configured port,
122
+
- a range tuple/list (e.g. (2000, 3000)) to pick a random available port from that range,
123
+
- a set/list of ports (e.g. {4002, 4003}) to pick a random port from the set,
124
+
- a list combining ranges and sets (e.g. [(2000,3000), {4002,4003}]).
125
+
postgres_options (str | None): Additional options for the PostgreSQL server process passed through pg_ctl.
126
+
load (list[Callable | str | Path] | None): Initialization steps applied to the template database before tests run; each element is either a callable or a path/SQL identifier that DatabaseJanitor.load understands.
127
+
128
+
Returns:
129
+
Callable[[FixtureRequest, TempPathFactory], Iterator[PostgreSQLExecutor]]: A pytest fixture factory that yields a started PostgreSQLExecutor configured per the provided arguments and test configuration.
Create, start, and yield a PostgreSQL server process configured for the requesting test.
138
+
139
+
This fixture selects an available port, prepares a data directory and logfile, starts a PostgreSQL server via PostgreSQLExecutor, applies any configured initialization/load steps, and yields the running executor to the test. The server is stopped and resources are cleaned up when the fixture context exits.
140
+
141
+
Returns:
142
+
PostgreSQLExecutor: A configured and started executor connected to the test PostgreSQL instance.
"""Check that the error gets raised on unsupported postgres version."""
52
+
"""
53
+
Verify that starting an executor with an unsupported PostgreSQL version raises PostgreSQLUnsupported.
54
+
55
+
Creates a PatchedPostgreSQLExecutor configured to simulate an unsupported server version and asserts that invoking its start() method raises `PostgreSQLUnsupported`.
"""Test whether the executor initializes properly."""
82
+
"""
83
+
Verify that a PostgreSQLExecutor initialized with a password and database name can start and stop successfully when running under the specified locale.
84
+
85
+
The test sets LC_ALL to `locale`, prepares a temporary data directory and logfile, constructs a PostgreSQLExecutor using the test configuration and provided credentials, and asserts the executor can start and stop.
86
+
87
+
Parameters:
88
+
locale (str): Locale string to set for the test environment (e.g., "en_US.UTF-8").
0 commit comments