Skip to content

Adapt to getfixturedefs change in pytest 8.1 #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

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

2.6.0
----------
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ inflection = "*"
factory_boy = ">=2.10.0"
pytest = ">=6.2"
typing_extensions = "*"
packaging = "*"

[tool.poetry.group.dev.dependencies]
mypy = ">=1.4.1"
Expand Down
21 changes: 20 additions & 1 deletion pytest_factoryboy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import pathlib
import sys
from collections.abc import Sequence
from importlib.metadata import version

__all__ = ("PostGenerationContext", "path_with_stem")
from _pytest.fixtures import FixtureDef, FixtureManager
from _pytest.nodes import Node
from packaging.version import parse as parse_version

pytest_version = parse_version(version("pytest"))

__all__ = ("PostGenerationContext", "path_with_stem", "getfixturedefs")

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

def path_with_stem(path: pathlib.Path, stem: str) -> pathlib.Path:
return path.with_name(stem + path.suffix)


if pytest_version.release >= (8, 1):

def getfixturedefs(fixturemanager: FixtureManager, fixturename: str, node: Node) -> Sequence[FixtureDef] | None:
return fixturemanager.getfixturedefs(fixturename, node)

else:

def getfixturedefs(fixturemanager: FixtureManager, fixturename: str, node: Node) -> Sequence[FixtureDef] | None:
return fixturemanager.getfixturedefs(fixturename, node.nodeid)
5 changes: 4 additions & 1 deletion pytest_factoryboy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import pytest

from .compat import getfixturedefs

if TYPE_CHECKING:
from typing import Any

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

for fixturedef in request._fixturemanager.getfixturedefs(fixture, request._pyfuncitem.parent.nodeid) or []:
fixturedefs = getfixturedefs(request._fixturemanager, fixture, request._pyfuncitem.parent)
for fixturedef in fixturedefs or []:
for argname in fixturedef.argnames:
if argname not in deps:
deps.add(argname)
Expand Down