-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add reference docs for pytest.mark.usefixtures #3663
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
Add reference docs for pytest.mark.usefixtures #3663
Conversation
|
||
**Tutorial**: :ref:`usefixtures`. | ||
|
||
Mark a test function as using the given fixture names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it could be a good idea to add an explicit warning/reminder here that you can only mark test functions like this and not other fixtures to address #1014
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh good idea, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like:
"Be aware that although you can use fixtures from oher fixtures by adding them to the function parameters, you can not do this by marking the fixture function with usefixtures
."
Maybe even with an example?
This works:
@pytest.fixture
def my_fixture(my_other_fixture):
[...]
This will not yield the wanted result and currently not result in an error or a warning either.
@pytest.mark.usefixtures("my_other_fixture")
@pytest.fixture
def my_fixture_that_sadly_wont_use_my_other_fixture():
[...]
I would even suggest to put this in a warning box, because this can be surprising even for experienced pytest users, especially due to the lack of an error atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @obestwalter!
I added the warning but the example I added to the tutorial/normal documentation. IMHO we should keep the reference as lean as possible.
|
||
This mark can be used with *test functions* only, having no affect when applied | ||
to a **fixture** function. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect :)
No description provided.