Skip to content

Commit

Permalink
Prevented the pytest plugin from crashing on pytest < 7.0
Browse files Browse the repository at this point in the history
Fixes #343.
  • Loading branch information
agronholm committed May 26, 2024
1 parent d8b0292 commit 72ec4e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/userguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ functions with :data:`~typing.Any`.
Using the pytest plugin
-----------------------

Typeguard comes with a pytest plugin that installs the import hook (explained in the
previous section). To use it, run ``pytest`` with the appropriate
Typeguard comes with a plugin for pytest (v7.0 or newer) that installs the import hook
(explained in the previous section). To use it, run ``pytest`` with the appropriate
``--typeguard-packages`` option. For example, if you wanted to instrument the
``foo.bar`` and ``xyz`` packages for type checking, you can do the following:

Expand Down
2 changes: 2 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This library adheres to
(`#460 <https://github.com/agronholm/typeguard/issues/460>`_; PR by @JelleZijlstra)
- Fixed test suite incompatibility with pytest 8.2
(`#461 <https://github.com/agronholm/typeguard/issues/461>`_)
- Fixed pytest plugin crashing on pytest version older than v7.0.0 (even if it's just
present) (`#343 <https://github.com/agronholm/typeguard/issues/343>`_)

**4.2.1** (2023-03-24)

Expand Down
7 changes: 4 additions & 3 deletions src/typeguard/_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import sys
import warnings
from typing import Any, Literal

from pytest import Config, Parser
from typing import TYPE_CHECKING, Any, Literal

from typeguard._config import CollectionCheckStrategy, ForwardRefPolicy, global_config
from typeguard._exceptions import InstrumentationWarning
from typeguard._importhook import install_import_hook
from typeguard._utils import qualified_name, resolve_reference

if TYPE_CHECKING:
from pytest import Config, Parser


def pytest_addoption(parser: Parser) -> None:
def add_ini_option(
Expand Down

0 comments on commit 72ec4e7

Please sign in to comment.