Skip to content

Commit 9790d91

Browse files
authored
Merge pull request #213 from bluetech/pytest81-fix
Adapt to `getfixturedefs` change in pytest 8.1
2 parents 03eeebf + 450d857 commit 9790d91

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Changelog
33

44
Unreleased
55
----------
6+
- Address compatibility issue with pytest 8.1. `#213 <https://github.com/pytest-dev/pytest-bdd/pull/213>`_
67

78
2.6.0
89
----------

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ inflection = "*"
3636
factory_boy = ">=2.10.0"
3737
pytest = ">=6.2"
3838
typing_extensions = "*"
39+
packaging = "*"
3940

4041
[tool.poetry.group.dev.dependencies]
4142
mypy = ">=1.4.1"

pytest_factoryboy/compat.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
import pathlib
44
import sys
5+
from collections.abc import Sequence
6+
from importlib.metadata import version
57

6-
__all__ = ("PostGenerationContext", "path_with_stem")
8+
from _pytest.fixtures import FixtureDef, FixtureManager
9+
from _pytest.nodes import Node
10+
from packaging.version import parse as parse_version
11+
12+
pytest_version = parse_version(version("pytest"))
13+
14+
__all__ = ("PostGenerationContext", "path_with_stem", "getfixturedefs")
715

816
try:
917
from factory.declarations import PostGenerationContext
@@ -19,3 +27,14 @@ def path_with_stem(path: pathlib.Path, stem: str) -> pathlib.Path:
1927

2028
def path_with_stem(path: pathlib.Path, stem: str) -> pathlib.Path:
2129
return path.with_name(stem + path.suffix)
30+
31+
32+
if pytest_version.release >= (8, 1):
33+
34+
def getfixturedefs(fixturemanager: FixtureManager, fixturename: str, node: Node) -> Sequence[FixtureDef] | None:
35+
return fixturemanager.getfixturedefs(fixturename, node)
36+
37+
else:
38+
39+
def getfixturedefs(fixturemanager: FixtureManager, fixturename: str, node: Node) -> Sequence[FixtureDef] | None:
40+
return fixturemanager.getfixturedefs(fixturename, node.nodeid)

pytest_factoryboy/plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import pytest
88

9+
from .compat import getfixturedefs
10+
911
if TYPE_CHECKING:
1012
from typing import Any
1113

@@ -48,7 +50,8 @@ def get_deps(self, request: SubRequest, fixture: str, deps: set[str] | None = No
4850
if fixture == "request":
4951
return deps
5052

51-
for fixturedef in request._fixturemanager.getfixturedefs(fixture, request._pyfuncitem.parent.nodeid) or []:
53+
fixturedefs = getfixturedefs(request._fixturemanager, fixture, request._pyfuncitem.parent)
54+
for fixturedef in fixturedefs or []:
5255
for argname in fixturedef.argnames:
5356
if argname not in deps:
5457
deps.add(argname)

0 commit comments

Comments
 (0)