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
Multiple step scenarios targeting the same fixture doesn't update the fixture #689
Comments
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: 7.0.1...7.1.2 file I simply copied the 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
The text was updated successfully, but these errors were encountered: