Open mawaliya opened 2 months ago
We are seeing this too, combinations tested that failed to behave as expected:
Downgrading to pytest 7.4.4 fixes it.
I don't have time to open a pull request right now, will try to eventually but this seems to work (I modified the file locally in my venv and executed my BDD tests and they all pass with pytest-bdd 7.1.2 and pytest 8.2.0).
Changes between releases 7.0.1 and 7.1.2: https://github.com/pytest-dev/pytest-bdd/compare/7.0.1...7.1.2
file src/pytest_bdd/compat.py
has been added with two methods to register a fixture, one for pytest 8.1+ and one for older pytest version.
I simply copied the inject_fixture
function from pytest < 8.1 and adapted the arguments to create the FixtureDef
with the correct arguments since pytest 8.1 and left the rest as is and it seems to work:
def inject_fixture(request: FixtureRequest, arg: str, value: Any) -> None:
"""Inject fixture into pytest fixture request.
:param request: pytest fixture request
:param arg: argument name
:param value: argument value
"""
fd = FixtureDef(
config=request._fixturemanager.config,
baseid=request.node.nodeid,
argname=arg,
func=lambda: value,
scope="function",
params=None,
ids=None,
_ispytest=True,
)
fd.cached_result = (value, 0, None)
old_fd = request._fixture_defs.get(arg)
add_fixturename = arg not in request.fixturenames
def fin() -> None:
request._fixturemanager._arg2fixturedefs[arg].remove(fd)
if old_fd is not None:
request._fixture_defs[arg] = old_fd
if add_fixturename:
request._pyfuncitem._fixtureinfo.names_closure.remove(arg)
request.addfinalizer(fin)
# inject fixture definition
request._fixturemanager._arg2fixturedefs.setdefault(arg, []).append(fd)
# inject fixture value in request cache
request._fixture_defs[arg] = fd
if add_fixturename:
request._pyfuncitem._fixtureinfo.names_closure.append(arg)
If someone wants to open a PR and make sure it doesn't break anything please feel free to do so. Otherwise I'll get to it eventually...
Cheers,
I created the PR
Env: Pytest 8.1.1 Pytest-bdd 7.1.2
more details
Issue: when having multiple steps pointing to the same target_fixture, it's not getting updated, it seems it is only updated once when it is set for the first time. On pytest 7.4.2 and pytest-bdd 7.0.0 this works as expected
code to reproduce.
I am expecting the scenario above to pass, but it will fail