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
  • Loading branch information
phillipuniverse committed Feb 18, 2024
1 parent c5304d3 commit 13a8b81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/897.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add your info here
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 13a8b81

Please sign in to comment.