-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed placements of the warnings to be in fixture, changed warning me…
…ssage from using string concat to f-strings for more readability, and added a function in compat to grab default parameters and its values
- Loading branch information
1 parent
2d991b5
commit 8b4bd3a
Showing
4 changed files
with
88 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from _pytest.pytester import Pytester | ||
|
||
def test_no_default_argument(pytester: Pytester) -> None: | ||
pytester.makepyfile( | ||
""" | ||
def test_with_default_param(param): | ||
assert param == 42 | ||
""" | ||
) | ||
result = pytester.runpytest() | ||
result.stdout.fnmatch_lines([ | ||
"*fixture 'param' not found*" | ||
]) | ||
|
||
|
||
def test_default_argument_warning(pytester: Pytester) -> None: | ||
pytester.makepyfile( | ||
""" | ||
def test_with_default_param(param=42): | ||
assert param == 42 | ||
""" | ||
) | ||
result = pytester.runpytest() | ||
result.stdout.fnmatch_lines([ | ||
"*PytestDefaultArgumentWarning: Test function 'test_with_default_param' has a default argument 'param=42'.*" | ||
]) | ||
|
||
|
||
def test_no_warning_for_no_default_param(pytester: Pytester) -> None: | ||
pytester.makepyfile( | ||
""" | ||
def test_without_default_param(param): | ||
assert param is None | ||
""" | ||
) | ||
result = pytester.runpytest() | ||
assert "PytestDefaultArgumentWarning" not in result.stdout.str() | ||
|
||
|
||
def test_warning_for_multiple_default_params(pytester: Pytester) -> None: | ||
pytester.makepyfile( | ||
""" | ||
def test_with_multiple_defaults(param1=42, param2="default"): | ||
assert param1 == 42 | ||
assert param2 == "default" | ||
""" | ||
) | ||
result = pytester.runpytest() | ||
result.stdout.fnmatch_lines([ | ||
"*PytestDefaultArgumentWarning: Test function 'test_with_multiple_defaults' has a default argument 'param1=42'.*", | ||
"*PytestDefaultArgumentWarning: Test function 'test_with_multiple_defaults' has a default argument 'param2=default'.*" | ||
]) |