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

Unexpected or undocumented behavior of pytest.mark.parametrize? #9889

Closed
Thomasillo opened this issue Apr 25, 2022 · 8 comments
Closed

Unexpected or undocumented behavior of pytest.mark.parametrize? #9889

Thomasillo opened this issue Apr 25, 2022 · 8 comments
Labels
topic: fixtures anything involving fixtures directly or indirectly topic: parametrize related to @pytest.mark.parametrize type: docs documentation improvement, missing or needing clarification type: question general question, might be closed after 2 weeks of inactivity

Comments

@Thomasillo
Copy link

Consider the following file test_stuff.py

import pytest

@pytest.fixture(scope="function")
def fixt_1():
    return 7

@pytest.fixture(scope="function")
def fixt_2(fixt_1):
    return fixt_1 * 2

@pytest.mark.parametrize("fixt_1", [4, 5])
def test_stuff(fixt_2):
    assert fixt_2 < 10

The second case fails, the first does not.
If this is intended behavior, I couldn't find documentation about this.

pytest version: 6.2.5

@Zac-HD Zac-HD added type: question general question, might be closed after 2 weeks of inactivity type: docs documentation improvement, missing or needing clarification topic: parametrize related to @pytest.mark.parametrize topic: fixtures anything involving fixtures directly or indirectly labels Apr 26, 2022
@asottile
Copy link
Member

8 is less than 10 but 10 is not less than 10 -- seems expected?

@Thomasillo
Copy link
Author

8 is less than 10 but 10 is not less than 10 -- seems expected?

Absolutely, no PhD in math necessary for that.

What is not expected resp. undocumented is the possibility to use pytest.mark.parametrize to parametrize the return value of a fixture that is only indirectly used by the parametrized test.

@asottile
Copy link
Member

oh true, it is overwriting a fixture that does seem wrong

@nicoddemus
Copy link
Member

nicoddemus commented Apr 27, 2022

Yes, this is an "undocumented" feature (I'm putting that in quotes because seems mostly like an accident in implementation IMO). I think we discussed this in the past, either to change the behavior, document it, or leave it undocumented, don't have the time to dig and find the issue right now unfortunately.

@asottile
Copy link
Member

looks like this is a dupe of #5712

@nicoddemus
Copy link
Member

Ahh right, thanks for digging it up @asottile!

@The-Compiler
Copy link
Member

Should we close this then?

@nicoddemus
Copy link
Member

Yes, thanks @The-Compiler!

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 topic: parametrize related to @pytest.mark.parametrize type: docs documentation improvement, missing or needing clarification type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

5 participants