-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cannot create two fixtures based on the same function #1875
Comments
Hi, Unfortunately this is not possible with current pytest because the Closing this as this can't be reliably fixed in current pytest (or even if it is worth doing at all TBH), but feel free to reopen if you still have questions. |
Thanks. Will consider other approaches. |
pytest-dev/pytest#1875 made it impossible to declare a function as a fixture multiple times, which we were doing across different modules. The fix was to move our @pytest.fixture calls into decorators in the tests/fixtures.py module.
Would be nice if it was possible, I'm not sure at all how feasible, to have some sort of useful error message when one tries to do that. I was trying to reuse a code just like in the example here, two fixtures calling the same function which spun up a local server, and pytest didn't tell me anything, I just saw that the server didn't go up, and took me a while to figure out what was wrong (that's on me as well, don't get me wrong). |
@nicoddemus given that we no longer return the actual function, it should be permissible to allow this now |
👍 |
I am not sure I should be able to do this, but I am wondering why not.
Code is below. What I would like to do is create two fixtures, but both are based on the same fixture function. However, the second one is stomping on the first one, as demonstrated below. I would have thought I would get
First is None
, but instead getNot First is None
Code:
Run:
pip list:
System info:
The text was updated successfully, but these errors were encountered: