Skip to content

Commit

Permalink
Allow the postgresql client to have user-specified scope
Browse files Browse the repository at this point in the history
Fixes #895
  • Loading branch information
phillipuniverse committed Feb 18, 2024
1 parent c5304d3 commit dcd03ad
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pytest_postgresql/factories/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import psycopg
import pytest
from _pytest.scope import _ScopeName
from psycopg import Connection
from pytest import FixtureRequest

Expand All @@ -33,21 +34,23 @@
def postgresql(
process_fixture_name: str,
dbname: Optional[str] = None,
scope: _ScopeName = "function",
load: Optional[List[Union[Callable, str, Path]]] = None,
isolation_level: "Optional[psycopg.IsolationLevel]" = None,
) -> Callable[[FixtureRequest], Iterator[Connection]]:
"""Return connection fixture factory for PostgreSQL.
:param process_fixture_name: name of the process fixture
:param dbname: database name
:param scope: which scope the fixture should be created for
:param load: SQL, function or function import paths to automatically load
into our test database
:param isolation_level: optional postgresql isolation level
defaults to server's default
: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.
Expand Down

0 comments on commit dcd03ad

Please sign in to comment.