-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for specifying options for the pytest plugin via pytest…
… config files Closes #440.
- Loading branch information
Showing
5 changed files
with
121 additions
and
12 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
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,63 @@ | ||
from textwrap import dedent | ||
|
||
from pytest import Pytester | ||
|
||
from typeguard import CollectionCheckStrategy, ForwardRefPolicy, config | ||
|
||
|
||
def test_config_options(pytester: Pytester) -> None: | ||
pytester.makepyprojecttoml( | ||
''' | ||
[tool.pytest.ini_options] | ||
typeguard-packages = """ | ||
mypackage | ||
otherpackage""" | ||
typeguard-debug-instrumentation = true | ||
typeguard-typecheck-fail-callback = "mypackage:failcallback" | ||
typeguard-forward-ref-policy = "ERROR" | ||
typeguard-collection-check-strategy = "ALL_ITEMS" | ||
''' | ||
) | ||
pytester.makepyfile( | ||
mypackage=( | ||
dedent( | ||
""" | ||
def failcallback(): | ||
pass | ||
""" | ||
) | ||
) | ||
) | ||
|
||
pytester.plugins = ["typeguard"] | ||
pytester.syspathinsert() | ||
pytestconfig = pytester.parseconfigure() | ||
assert pytestconfig.getini("typeguard-packages") == ["mypackage", "otherpackage"] | ||
assert config.typecheck_fail_callback.__name__ == "failcallback" | ||
assert config.debug_instrumentation is True | ||
assert config.forward_ref_policy is ForwardRefPolicy.ERROR | ||
assert config.collection_check_strategy is CollectionCheckStrategy.ALL_ITEMS | ||
|
||
|
||
def test_commandline_options(pytester: Pytester) -> None: | ||
pytester.makepyfile( | ||
mypackage=( | ||
dedent( | ||
""" | ||
def failcallback(): | ||
pass | ||
""" | ||
) | ||
) | ||
) | ||
|
||
pytester.plugins = ["typeguard"] | ||
pytester.syspathinsert() | ||
pytestconfig = pytester.parseconfigure( | ||
"--typeguard-packages=mypackage,otherpackage" | ||
) | ||
assert pytestconfig.getoption("typeguard_packages") == "mypackage,otherpackage" | ||
assert config.typecheck_fail_callback.__name__ == "failcallback" | ||
assert config.debug_instrumentation is True | ||
assert config.forward_ref_policy is ForwardRefPolicy.ERROR | ||
assert config.collection_check_strategy is CollectionCheckStrategy.ALL_ITEMS |