Skip to content

Commit

Permalink
Fixed pytest plugin tests
Browse files Browse the repository at this point in the history
They were messing with the global configuration, and the command line options test didn't have the proper input either.
  • Loading branch information
agronholm committed Mar 23, 2024
1 parent ded1a04 commit d51d8bc
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from textwrap import dedent

from pytest import Pytester
import pytest
from pytest import MonkeyPatch, Pytester

from typeguard import CollectionCheckStrategy, ForwardRefPolicy, config
from typeguard import CollectionCheckStrategy, ForwardRefPolicy, TypeCheckConfiguration


def test_config_options(pytester: Pytester) -> None:
@pytest.fixture
def config(monkeypatch: MonkeyPatch) -> TypeCheckConfiguration:
config = TypeCheckConfiguration()
monkeypatch.setattr("typeguard._pytest_plugin.global_config", config)
return config


def test_config_options(pytester: Pytester, config: TypeCheckConfiguration) -> None:
pytester.makepyprojecttoml(
'''
[tool.pytest.ini_options]
Expand Down Expand Up @@ -39,7 +47,9 @@ def failcallback():
assert config.collection_check_strategy is CollectionCheckStrategy.ALL_ITEMS


def test_commandline_options(pytester: Pytester) -> None:
def test_commandline_options(
pytester: Pytester, config: TypeCheckConfiguration
) -> None:
pytester.makepyfile(
mypackage=(
dedent(
Expand All @@ -54,7 +64,11 @@ def failcallback():
pytester.plugins = ["typeguard"]
pytester.syspathinsert()
pytestconfig = pytester.parseconfigure(
"--typeguard-packages=mypackage,otherpackage"
"--typeguard-packages=mypackage,otherpackage",
"--typeguard-typecheck-fail-callback=mypackage:failcallback",
"--typeguard-debug-instrumentation",
"--typeguard-forward-ref-policy=ERROR",
"--typeguard-collection-check-strategy=ALL_ITEMS",
)
assert pytestconfig.getoption("typeguard_packages") == "mypackage,otherpackage"
assert config.typecheck_fail_callback.__name__ == "failcallback"
Expand Down

0 comments on commit d51d8bc

Please sign in to comment.