Skip to content

Commit 13a8b81

Browse files
Allow the postgresql client to have user-specified scope
Fixes #895
1 parent c5304d3 commit 13a8b81

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

newsfragments/897.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add your info here

pytest_postgresql/factories/client.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import psycopg
2424
import pytest
25+
from _pytest.scope import _ScopeName
2526
from psycopg import Connection
2627
from pytest import FixtureRequest
2728

@@ -33,21 +34,23 @@
3334
def postgresql(
3435
process_fixture_name: str,
3536
dbname: Optional[str] = None,
37+
scope: _ScopeName = "function",
3638
load: Optional[List[Union[Callable, str, Path]]] = None,
3739
isolation_level: "Optional[psycopg.IsolationLevel]" = None,
3840
) -> Callable[[FixtureRequest], Iterator[Connection]]:
3941
"""Return connection fixture factory for PostgreSQL.
4042
4143
:param process_fixture_name: name of the process fixture
4244
:param dbname: database name
45+
:param scope: which scope the fixture should be created for
4346
:param load: SQL, function or function import paths to automatically load
4447
into our test database
4548
:param isolation_level: optional postgresql isolation level
4649
defaults to server's default
4750
:returns: function which makes a connection to postgresql
4851
"""
4952

50-
@pytest.fixture
53+
@pytest.fixture(scope=scope)
5154
def postgresql_factory(request: FixtureRequest) -> Iterator[Connection]:
5255
"""Fixture factory for PostgreSQL.
5356

0 commit comments

Comments
 (0)