Skip to content

Commit 2c68ff8

Browse files
committed
fixup: attempt to stabilise tests around noproc
1 parent 34c0d4f commit 2c68ff8

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ You can create additional fixtures using factories:
101101
.. note::
102102

103103
Each process fixture can be configured independently through factory arguments.
104+
When using chained fixtures (``postgresql_noproc(depends_on=...)``), the
105+
factory injects the dependency name into the runtime signature so
106+
pytest/xdist can order setup/teardown correctly. This may not show up in
107+
``--setup-show`` output, and some older pytest versions do not reflect the
108+
dynamic signature when displaying fixtures.
104109

105110
Pre-populating the database for tests
106111
-------------------------------------

pytest_postgresql/factories/client.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
1818
"""Fixture factory for postgresql client."""
1919

20-
import inspect
21-
from typing import Any, Callable, Iterator
20+
from typing import Callable, Iterator
2221

2322
import psycopg
2423
import pytest
@@ -46,7 +45,7 @@ def postgresql(
4645
"""
4746

4847
@pytest.fixture
49-
def postgresql_factory(request: FixtureRequest, **kwargs: Any) -> Iterator[Connection]:
48+
def postgresql_factory(request: FixtureRequest) -> Iterator[Connection]:
5049
"""Fixture factory for PostgreSQL.
5150
5251
:param request: fixture request object
@@ -85,11 +84,4 @@ def postgresql_factory(request: FixtureRequest, **kwargs: Any) -> Iterator[Conne
8584
yield db_connection
8685
db_connection.close()
8786

88-
# Expose process fixture dependency to pytest for correct teardown ordering.
89-
postgresql_factory.__signature__ = inspect.Signature( # type: ignore[attr-defined]
90-
parameters=[
91-
inspect.Parameter("request", inspect.Parameter.POSITIONAL_OR_KEYWORD),
92-
inspect.Parameter(process_fixture_name, inspect.Parameter.POSITIONAL_OR_KEYWORD),
93-
]
94-
)
9587
return postgresql_factory

pytest_postgresql/factories/noprocess.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# along with pytest-postgresql. If not, see <http://www.gnu.org/licenses/>.
1818
"""Fixture factory for existing postgresql server."""
1919

20+
import inspect
2021
import os
2122
from pathlib import Path
2223
from typing import Callable, Iterator
@@ -121,4 +122,12 @@ def postgresql_noproc_fixture(request: FixtureRequest) -> Iterator[NoopExecutor]
121122
janitor.load(load_element)
122123
yield noop_exec
123124

125+
if depends_on and depends_on.isidentifier():
126+
postgresql_noproc_fixture.__signature__ = inspect.Signature( # type: ignore[attr-defined]
127+
parameters=[
128+
inspect.Parameter("request", inspect.Parameter.POSITIONAL_OR_KEYWORD),
129+
inspect.Parameter(depends_on, inspect.Parameter.POSITIONAL_OR_KEYWORD),
130+
]
131+
)
132+
124133
return postgresql_noproc_fixture

0 commit comments

Comments
 (0)