-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples how to depend on all instances of a parametrized test.
Related to Issue #9.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
|
||
def instances(name, params): | ||
def vstr(val): | ||
if isinstance(val, (list, tuple)): | ||
return "-".join([str(v) for v in val]) | ||
else: | ||
return str(val) | ||
return ["%s[%s]" % (name, vstr(v)) for v in params] | ||
|
||
|
||
params_a = range(17) | ||
|
||
@pytest.mark.parametrize("x", params_a) | ||
@pytest.mark.dependency() | ||
def test_a(x): | ||
if x == 13: | ||
pytest.xfail("deliberate fail") | ||
assert False | ||
else: | ||
pass | ||
|
||
@pytest.mark.dependency(depends=instances("test_a", params_a)) | ||
def test_b(): | ||
pass | ||
|
||
params_c = zip(range(0,8,2), range(2,6)) | ||
|
||
@pytest.mark.parametrize("x,y", params_c) | ||
@pytest.mark.dependency() | ||
def test_c(x, y): | ||
if x > y: | ||
pytest.xfail("deliberate fail") | ||
assert False | ||
else: | ||
pass | ||
|
||
@pytest.mark.dependency(depends=instances("test_c", params_c)) | ||
def test_d(): | ||
pass | ||
|
||
params_e = ['abc', 'def'] | ||
|
||
@pytest.mark.parametrize("s", params_e) | ||
@pytest.mark.dependency() | ||
def test_e(s): | ||
if 'e' in s: | ||
pytest.xfail("deliberate fail") | ||
assert False | ||
else: | ||
pass | ||
|
||
@pytest.mark.dependency(depends=instances("test_e", params_e)) | ||
def test_f(): | ||
pass |
This file contains 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