Skip to content

Commit 72ec4e7

Browse files
committed
Prevented the pytest plugin from crashing on pytest < 7.0
Fixes #343.
1 parent d8b0292 commit 72ec4e7

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

docs/userguide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ functions with :data:`~typing.Any`.
148148
Using the pytest plugin
149149
-----------------------
150150

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

docs/versionhistory.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This library adheres to
1111
(`#460 <https://github.com/agronholm/typeguard/issues/460>`_; PR by @JelleZijlstra)
1212
- Fixed test suite incompatibility with pytest 8.2
1313
(`#461 <https://github.com/agronholm/typeguard/issues/461>`_)
14+
- Fixed pytest plugin crashing on pytest version older than v7.0.0 (even if it's just
15+
present) (`#343 <https://github.com/agronholm/typeguard/issues/343>`_)
1416

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

src/typeguard/_pytest_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import sys
44
import warnings
5-
from typing import Any, Literal
6-
7-
from pytest import Config, Parser
5+
from typing import TYPE_CHECKING, Any, Literal
86

97
from typeguard._config import CollectionCheckStrategy, ForwardRefPolicy, global_config
108
from typeguard._exceptions import InstrumentationWarning
119
from typeguard._importhook import install_import_hook
1210
from typeguard._utils import qualified_name, resolve_reference
1311

12+
if TYPE_CHECKING:
13+
from pytest import Config, Parser
14+
1415

1516
def pytest_addoption(parser: Parser) -> None:
1617
def add_ini_option(

0 commit comments

Comments
 (0)