Add warning about generators for parametrizing class or module#13742
Closed
andrewwillowen wants to merge 2 commits intopytest-dev:mainfrom
Closed
Add warning about generators for parametrizing class or module#13742andrewwillowen wants to merge 2 commits intopytest-dev:mainfrom
andrewwillowen wants to merge 2 commits intopytest-dev:mainfrom
Conversation
Add warning about using generators as the value argument
for more information, see https://pre-commit.ci
Member
|
Hi @andrewwillowen, Your case seems different from @steadyfirmness's case which was running |
Author
|
Taking the example from the documentation. test.py import pytest
@pytest.mark.parametrize("n,expected", (i for i in [(1, 2), (3, 4)]))
class TestClass:
def test_simple_case(self, n, expected):
assert n + 1 == expected
def test_weird_simple_case(self, n, expected):
assert (n * 1) + 1 == expectedThen run pytest -rs ./test.py |
Member
|
Thanks. In order to keep the discussion in one place, I'll comment further in the issue #13409. |
Member
|
We ended up deprecating this case, see #13877. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I stumbled across this issue when trying to write some tests and took a while to figure out the issue.
Based on #13409, it sounds like this is expected behavior.
This PR adds a warning to https://docs.pytest.org/en/stable/how-to/parametrize.html so that hopefully other people don't waste cycles debugging this behavior.