Skip to content
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

Pytest 8.1.1 fixture injection compability #677

Closed
Tracked by #652
mp2218 opened this issue Mar 11, 2024 · 2 comments
Closed
Tracked by #652

Pytest 8.1.1 fixture injection compability #677

mp2218 opened this issue Mar 11, 2024 · 2 comments

Comments

@mp2218
Copy link

mp2218 commented Mar 11, 2024

Test which had fixture injection worked fine last week, but now with new pytest release breaks with following trace:

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(
fixturemanager=request._fixturemanager,
baseid=None,
argname=arg,
func=lambda: value,
scope="function",
params=None,
)
E TypeError: FixtureDef.init() got an unexpected keyword argument 'fixturemanager'
/opt/hostedtoolcache/Python/3.11.8/x64/lib/python3.11/site-packages/pytest_bdd/steps.py:213: TypeError

snippet of fixture injection:

@given("User does not have credit", target_fixture="fielding_page")
def no_money(context_logged_in, base_url):
return Fielding_Page(context_logged_in.new_page(), base_url)

Version: bdd-7.1.1
`

@mp2218 mp2218 changed the title Pytest 8.1.1 injection fixture compability Pytest 8.1.1 fixture injection compability Mar 11, 2024
@simbs
Copy link

simbs commented Mar 12, 2024

I ran into this yesterday as well. Here's the relevant pytest change, it's there from version 8.1.1

I was able to reproduce this locally running the pytest-bdd tests with the latest pytest version. I could also fix them by updating the call to FixtureDef in inject_fixture here: https://github.com/pytest-dev/pytest-bdd/blob/master/src/pytest_bdd/steps.py#L213

but obviously it then breaks compatibility with previous versions of pytest. The compat.py file is already addressing what looks like a related compatibility issue, with two different functions depending on whether pytest is below or above 8.1, so creating a function there that instantiates FixtureDef differently based on the version worked for me locally.

It's not the nicest solution, but I'm happy to open a PR with these changes if it'll help.

@youtux
Copy link
Contributor

youtux commented Mar 17, 2024

Fixed in #680. I just released version 7.1.2 with the fix

@youtux youtux closed this as completed Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants