Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add:
get_all_cases
extended to support filtering and use other modu…
…les as `parametrization_target` (#260) * Add: `get_all_cases` doesn't require parametrization target * Fix: Make any `parametrization_target` required for string module ref * Fix: bad variables name * Add: testing for string module references and AUTO * Add: Use explicit module object with `get_all_cases`
- Loading branch information
1 parent
904b02a
commit e960630
Showing
8 changed files
with
187 additions
and
22 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
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
Empty file.
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,12 @@ | ||
# Imported explicitly or with ".cases" | ||
from pytest_cases import case | ||
|
||
|
||
@case | ||
def case_1(): | ||
return "hello ." | ||
|
||
|
||
@case | ||
def case_2(): | ||
return "hi ." |
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,12 @@ | ||
# Import with AUTO | ||
from pytest_cases import case | ||
|
||
|
||
@case | ||
def case_1(): | ||
return "hello AUTO" | ||
|
||
|
||
@case | ||
def case_2(): | ||
return "hi AUTO" |
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,13 @@ | ||
# Used by passing the corresponding module `test_other` to `get_all_cases` | ||
# `get_all_cases(test_other)` | ||
from pytest_cases import case | ||
|
||
|
||
@case | ||
def case_1(): | ||
return "hello cases_other" | ||
|
||
|
||
@case | ||
def case_2(): | ||
return "hi cases_other" |
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,80 @@ | ||
from pytest_cases import (AUTO, case, get_all_cases, parametrize, | ||
parametrize_with_cases) | ||
|
||
|
||
@case(tags=["a", "banana"]) | ||
def case_1(): | ||
return "a_banana" | ||
|
||
|
||
@case(tags=["a"]) | ||
def case_2(): | ||
return "a" | ||
|
||
|
||
@case(tags=["b", "banana"]) | ||
def case_3(): | ||
return "b_banana" | ||
|
||
|
||
@case(tags=["b"]) | ||
def case_4(): | ||
return "b" | ||
|
||
|
||
all_cases = get_all_cases(cases=[case_1, case_2, case_3, case_4]) | ||
a_cases = get_all_cases(cases=all_cases, has_tag="a") | ||
b_cases = get_all_cases(cases=all_cases, has_tag="b") | ||
banana_cases = get_all_cases(cases=a_cases + b_cases, has_tag=["banana"]) | ||
|
||
|
||
# Test behaviour with explicit cases and no parametrization target | ||
################################################################## | ||
@parametrize_with_cases("word", cases=all_cases) | ||
def test_all(word): | ||
assert word in ["a", "a_banana", "b", "b_banana"] | ||
|
||
|
||
@parametrize_with_cases("word", cases=a_cases) | ||
def test_a(word): | ||
assert "a" in word | ||
|
||
|
||
@parametrize_with_cases("word", cases=b_cases) | ||
def test_b(word): | ||
assert "b" in word | ||
|
||
|
||
@parametrize_with_cases("word", cases=banana_cases) | ||
def test_banana(word): | ||
assert "banana" in word | ||
|
||
|
||
# Test behaviour with string module ref and AUTO and no parametrization target | ||
############################################################################## | ||
def test_this_module_cases(): | ||
this_module_cases = get_all_cases(cases=".") | ||
assert set(this_module_cases) == {case_1, case_2, case_3, case_4} | ||
|
||
|
||
def test_relative_module_cases(): | ||
relative_import_cases = get_all_cases(cases=".cases") | ||
assert {"hello .", "hi ."} == {f() for f in relative_import_cases} | ||
|
||
|
||
def test_auto_cases(): | ||
auto_import_cases = get_all_cases(cases=AUTO) | ||
assert {"hello AUTO", "hi AUTO"} == {f() for f in auto_import_cases} | ||
|
||
|
||
# Test behaviour with an explicit module parametrization target | ||
############################################################### | ||
from tests.cases.issues.issue_258 import test_other | ||
def test_module_parametrization_auto(): | ||
cases_other_cases = get_all_cases(test_other, cases=AUTO) | ||
assert {"hello cases_other", "hi cases_other"} == {f() for f in cases_other_cases} | ||
|
||
|
||
def test_module_parametrization_this_module(): | ||
test_other_cases = get_all_cases(test_other, cases='.') | ||
assert {"hello test_other", "hi test_other"} == {f() for f in test_other_cases} |
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,11 @@ | ||
from pytest_cases import case | ||
|
||
|
||
@case | ||
def case_1(): | ||
return "hello test_other" | ||
|
||
|
||
@case | ||
def case_2(): | ||
return "hi test_other" |