-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix pytest.mark.parametrize when the argvalue is an iterator
#5356
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix ``pytest.mark.parametrize`` when the argvalues is an iterator. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -413,6 +413,28 @@ def test_func(a, b): | |
| assert result.ret == 0 | ||
|
|
||
|
|
||
| def test_parametrize_iterator(testdir): | ||
| """parametrize should work with generators (#5354).""" | ||
| py_file = testdir.makepyfile( | ||
| """\ | ||
| import pytest | ||
|
|
||
| def gen(): | ||
| yield 1 | ||
| yield 2 | ||
| yield 3 | ||
|
|
||
| @pytest.mark.parametrize('a', gen()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks down on marker/generator reuse
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RonnyPfannschmidt please consider creating a new issue - or do you know what's up with the comment, @asottile ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @RonnyPfannschmidt is suggesting this won't work (not at a computer) m = pytest.mark.parametrize('a', gen())
@m
def test1(a): pass
@m
def test2(a): pass
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But if it doesn't, it never worked so 🤷♂️ probably?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already had a issue about reuse of generators
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that example above is indeed broken, but wasn't the regression being targetted by this fix: $ pytest t.py -vv
============================= test session starts ==============================
platform linux -- Python 3.6.7, pytest-4.5.0, py-1.8.0, pluggy-0.12.0 -- /tmp/venv/bin/python3
cachedir: .pytest_cache
rootdir: /tmp
plugins: celery-4.3.0
collected 4 items
t.py::test1[1] PASSED [ 25%]
t.py::test1[2] PASSED [ 50%]
t.py::test1[3] PASSED [ 75%]
t.py::test2[a0] SKIPPED [100%]
===================== 3 passed, 1 skipped in 0.01 seconds ====================== |
||
| def test(a): | ||
| assert a >= 1 | ||
| """ | ||
| ) | ||
| result = testdir.runpytest(py_file) | ||
| assert result.ret == 0 | ||
| # should not skip any tests | ||
| result.stdout.fnmatch_lines(["*3 passed*"]) | ||
|
|
||
|
|
||
| class TestFunctional(object): | ||
| def test_merging_markers_deep(self, testdir): | ||
| # issue 199 - propagate markers into nested classes | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.