Skip to content

Commit

Permalink
Merge pull request #213 from bluetech/pytest81-fix
Browse files Browse the repository at this point in the history
Adapt to `getfixturedefs` change in pytest 8.1
  • Loading branch information
youtux authored Jan 21, 2024
2 parents 03eeebf + 450d857 commit 9790d91
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
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

0 comments on commit 9790d91

Please sign in to comment.