From 8dc315504e66e48cc319f85c6fd1b884ac4c268b Mon Sep 17 00:00:00 2001 From: FaeTheWolf Date: Mon, 17 Jun 2024 16:34:35 -0400 Subject: [PATCH] Permit variable-level scopes for client fixture. Sometimes a user might not *want* the client fixture to be function-scoped. For example, another fixture may rely on the connection info of the client, such as port-number, and might want that data to remain static throughout a session, or might need that data in a session-scoped fixture. --- pytest_postgresql/factories/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pytest_postgresql/factories/client.py b/pytest_postgresql/factories/client.py index d016c532..698c4f53 100644 --- a/pytest_postgresql/factories/client.py +++ b/pytest_postgresql/factories/client.py @@ -32,6 +32,7 @@ def postgresql( process_fixture_name: str, + scope: str = 'function', dbname: Optional[str] = None, load: Optional[List[Union[Callable, str, Path]]] = None, isolation_level: "Optional[psycopg.IsolationLevel]" = None, @@ -47,7 +48,7 @@ def postgresql( :returns: function which makes a connection to postgresql """ - @pytest.fixture + @pytest.fixture(scope=scope) def postgresql_factory(request: FixtureRequest) -> Iterator[Connection]: """Fixture factory for PostgreSQL.