Skip to content

Commit d51d8bc

Browse files
committed
Fixed pytest plugin tests
They were messing with the global configuration, and the command line options test didn't have the proper input either.
1 parent ded1a04 commit d51d8bc

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

tests/test_pytest_plugin.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from textwrap import dedent
22

3-
from pytest import Pytester
3+
import pytest
4+
from pytest import MonkeyPatch, Pytester
45

5-
from typeguard import CollectionCheckStrategy, ForwardRefPolicy, config
6+
from typeguard import CollectionCheckStrategy, ForwardRefPolicy, TypeCheckConfiguration
67

78

8-
def test_config_options(pytester: Pytester) -> None:
9+
@pytest.fixture
10+
def config(monkeypatch: MonkeyPatch) -> TypeCheckConfiguration:
11+
config = TypeCheckConfiguration()
12+
monkeypatch.setattr("typeguard._pytest_plugin.global_config", config)
13+
return config
14+
15+
16+
def test_config_options(pytester: Pytester, config: TypeCheckConfiguration) -> None:
917
pytester.makepyprojecttoml(
1018
'''
1119
[tool.pytest.ini_options]
@@ -39,7 +47,9 @@ def failcallback():
3947
assert config.collection_check_strategy is CollectionCheckStrategy.ALL_ITEMS
4048

4149

42-
def test_commandline_options(pytester: Pytester) -> None:
50+
def test_commandline_options(
51+
pytester: Pytester, config: TypeCheckConfiguration
52+
) -> None:
4353
pytester.makepyfile(
4454
mypackage=(
4555
dedent(
@@ -54,7 +64,11 @@ def failcallback():
5464
pytester.plugins = ["typeguard"]
5565
pytester.syspathinsert()
5666
pytestconfig = pytester.parseconfigure(
57-
"--typeguard-packages=mypackage,otherpackage"
67+
"--typeguard-packages=mypackage,otherpackage",
68+
"--typeguard-typecheck-fail-callback=mypackage:failcallback",
69+
"--typeguard-debug-instrumentation",
70+
"--typeguard-forward-ref-policy=ERROR",
71+
"--typeguard-collection-check-strategy=ALL_ITEMS",
5872
)
5973
assert pytestconfig.getoption("typeguard_packages") == "mypackage,otherpackage"
6074
assert config.typecheck_fail_callback.__name__ == "failcallback"

0 commit comments

Comments
 (0)