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
Add: get_all_cases
extended to support filtering and use other modules as parametrization_target
#260
Merged
smarie
merged 5 commits into
smarie:main
from
eddiebergman:add_optional_func_for_get_all_args
Mar 21, 2022
Merged
Add: get_all_cases
extended to support filtering and use other modules as parametrization_target
#260
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b387ac6
Add: `get_all_cases` doesn't require parametrization target
eddiebergman 83e442e
Fix: Make any `parametrization_target` required for string module ref
eddiebergman b04ab00
Fix: bad variables name
eddiebergman 73a29e8
Add: testing for string module references and AUTO
eddiebergman 142f06a
Add: Use explicit module object with `get_all_cases`
eddiebergman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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" |
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.
If
context
is not actually used anywhere in this function except as a way to read the module__name__
, then I suggest to replace it with an explicittest_module_name
argument.