-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Request #714: Apply indirect=True on particular argnames #908
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2fc7aed
Request #714: Apply indirect=True on particular argnames
Elizaveta239 9846953
Support for python 2.6
Elizaveta239 15b865f
Rewrite test using @pytest.fixture
Elizaveta239 54a3d62
Update CHANGELOG and AUTHORS
Elizaveta239 63bac67
Add test for bad value in argument 'indirect'
Elizaveta239 db9809d
Update test for error in 'indirect' parameter
Elizaveta239 657ca97
Some refactorings after code review
Elizaveta239 f7bacd1
Update docs
Elizaveta239 06585f5
Always report error about parametrize data that doesn't correspond to…
Elizaveta239 e67d66a
Merge branch 'pytest-dev'
Elizaveta239 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,17 +220,76 @@ def func(x, y): pass | |
assert metafunc._calls[0].id == "0-2" | ||
assert metafunc._calls[1].id == "0-3" | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect(self): | ||
def func(x, y): pass | ||
metafunc = self.Metafunc(func) | ||
metafunc.parametrize('x', [1], indirect=True) | ||
metafunc.parametrize('y', [2,3], indirect=True) | ||
metafunc.parametrize('unnamed', [1], indirect=True) | ||
assert len(metafunc._calls) == 2 | ||
assert metafunc._calls[0].funcargs == {} | ||
assert metafunc._calls[1].funcargs == {} | ||
assert metafunc._calls[0].params == dict(x=1,y=2, unnamed=1) | ||
assert metafunc._calls[1].params == dict(x=1,y=3, unnamed=1) | ||
assert metafunc._calls[0].params == dict(x=1,y=2) | ||
assert metafunc._calls[1].params == dict(x=1,y=3) | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect_list(self): | ||
def func(x, y): pass | ||
metafunc = self.Metafunc(func) | ||
metafunc.parametrize('x, y', [('a', 'b')], indirect=['x']) | ||
assert metafunc._calls[0].funcargs == dict(y='b') | ||
assert metafunc._calls[0].params == dict(x='a') | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect_list_all(self): | ||
def func(x, y): pass | ||
metafunc = self.Metafunc(func) | ||
metafunc.parametrize('x, y', [('a', 'b')], indirect=['x', 'y']) | ||
assert metafunc._calls[0].funcargs == {} | ||
assert metafunc._calls[0].params == dict(x='a', y='b') | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect_list_empty(self): | ||
def func(x, y): pass | ||
metafunc = self.Metafunc(func) | ||
metafunc.parametrize('x, y', [('a', 'b')], indirect=[]) | ||
assert metafunc._calls[0].funcargs == dict(x='a', y='b') | ||
assert metafunc._calls[0].params == {} | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect_list_functional(self, testdir): | ||
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. Nice test! It deserves a docstring so Future Us can understand why you've written it this way :) |
||
""" | ||
Test parametrization with 'indirect' parameter applied on | ||
particular arguments. | ||
|
||
:param testdir: the instance of Testdir class, a temporary | ||
test directory. | ||
""" | ||
testdir.makepyfile(""" | ||
import pytest | ||
@pytest.fixture(scope='function') | ||
def x(request): | ||
return request.param * 3 | ||
@pytest.fixture(scope='function') | ||
def y(request): | ||
return request.param * 2 | ||
@pytest.mark.parametrize('x, y', [('a', 'b')], indirect=['x']) | ||
def test_simple(x,y): | ||
assert len(x) == 3 | ||
assert len(y) == 1 | ||
""") | ||
result = testdir.runpytest("-v") | ||
result.stdout.fnmatch_lines([ | ||
"*test_simple*a-b*", | ||
"*1 passed*", | ||
]) | ||
|
||
@pytest.mark.issue714 | ||
def test_parametrize_indirect_list_error(self, testdir): | ||
def func(x, y): pass | ||
metafunc = self.Metafunc(func) | ||
with pytest.raises(ValueError): | ||
metafunc.parametrize('x, y', [('a', 'b')], indirect=['x', 'z']) | ||
|
||
def test_addcalls_and_parametrize_indirect(self): | ||
def func(x, y): pass | ||
|
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.
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.
Please add a docstring or in the name of the function, a reference to the issue number
These tests are good, but we need to test the error path relating to the "uses no fixture" error. I realise there is no test for that case even with indirect as boolean but it should be simple to add. We definitely want to check it when indirect is a sequence because I think at the moment the code is not actually checking that.