Skip to content

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

Merged
merged 2 commits into from
Jul 7, 2018

Conversation

nicoddemus
Copy link
Member

No description provided.

@coveralls
Copy link

coveralls commented Jul 7, 2018

Coverage Status

Coverage increased (+0.05%) to 92.65% when pulling d26a596 on nicoddemus:usefixtures-reference into 7e8f7bf on pytest-dev:master.


**Tutorial**: :ref:`usefixtures`.

Mark a test function as using the given fixture names.
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member

@obestwalter obestwalter Jul 7, 2018

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect :)

@nicoddemus nicoddemus merged commit aa9d1ad into pytest-dev:master Jul 7, 2018
@nicoddemus nicoddemus deleted the usefixtures-reference branch July 7, 2018 15:26
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

Successfully merging this pull request may close these issues.

3 participants