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

Please error when fixtures conflict #3346

Closed
smurfix opened this issue Mar 27, 2018 · 8 comments
Closed

Please error when fixtures conflict #3346

smurfix opened this issue Mar 27, 2018 · 8 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@smurfix
Copy link

smurfix commented Mar 27, 2018

The pytest_toolbox module also contains a caplog fixture, which broke a few of my tests. Finding that bug was no fun.

pytest should raise an error when it encounters conflicting fixtures.

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #201 (conflicting option string(s): --fixtures), #2726 (pytest_generate_tests conflicts with conftest.py fixtures), #2201 (Doc error in fixtures section), #1098 (Confusing error message around tmpdir fixture), and #2934 (capsysbinary fixture).

@The-Compiler
Copy link
Member

Overriding fixtures is also a feature, so I don't think that's possible.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 27, 2018
@smurfix
Copy link
Author

smurfix commented Mar 27, 2018

@The-Compiler Mark the overriding fixture as intentionally overriding, then. @pytest.mark.fixture_override or @pytest.mark.fixture(priority=True) would be two possible APIs for that.

@The-Compiler The-Compiler added type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature topic: fixtures anything involving fixtures directly or indirectly and removed type: bug problem that needs to be addressed labels Mar 27, 2018
@The-Compiler
Copy link
Member

That'd be a possibility, with an appropriate deprecation period.

@flub
Copy link
Member

flub commented Mar 27, 2018

Hmm, we don't mark fixtures, only test functions. But @pytest.fixture(replace=True) could be a possibility. Though coming up with a better name might be useful ;-)

This could make some plugins which provide the same fixture no longer co-installable though. Not sure if that exists in practice, the the lack of namespacing in fixtures doesn't make this too far fetched though. Making enabling this exclusion opt-in in pytest.ini might be a suitable solution though.

Would you mind having a go at a pull request for this? Feel free to ask questions! (also on freenode/#pylib on IRC)

@smurfix
Copy link
Author

smurfix commented Apr 2, 2018

I'll see what I can do, though frankly the pytest internals are not easy to understand and my time is limited. :-/

@RonnyPfannschmidt
Copy link
Member

@flub that topic in particular is so freakishly messy that i suspect 3-4 attempts each about 3-4 workdays are needed to sort out (marks was simpler)

@Zac-HD Zac-HD added the type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog label Nov 27, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Nov 27, 2019

Closing this in favor of #3966, which has a more detailed plan for what we should do and warn about when overriding fixtures.

@Zac-HD Zac-HD closed this as completed Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: fixtures anything involving fixtures directly or indirectly type: backward compatibility might present some backward compatibility issues which should be carefully noted in the changelog type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

6 participants