Skip to content

Commit

Permalink
Publish MonkeyPatch for typing
Browse files Browse the repository at this point in the history
This builds on the work done in 2bcad38
to add `MonkeyPatch` to pytest's public API. This will allow users of
pytest to annotation their tests like

    def test_some_code(monkeypatch: Generator[MonkeyPatch, None, None]) -> None:
        ...

To make this possible, the `monkeypatch` module can't import `pytest`
anymore. Instead it will import `PytestWarning` directly from
`_pytest.warning_types`.
  • Loading branch information
dirn committed Jul 6, 2020
1 parent ef62b86 commit b6363de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/_pytest/monkeypatch.py
Expand Up @@ -13,10 +13,10 @@
from typing import TypeVar
from typing import Union

import pytest
from _pytest.compat import overload
from _pytest.fixtures import fixture
from _pytest.pathlib import Path
from _pytest.warning_types import PytestWarning

RE_IMPORT_ERROR_NAME = re.compile(r"^No module named (.*)$")

Expand Down Expand Up @@ -272,7 +272,7 @@ def setenv(self, name: str, value: str, prepend: Optional[str] = None) -> None:
and prepend the ``value`` adjoined with the ``prepend`` character."""
if not isinstance(value, str):
warnings.warn(
pytest.PytestWarning(
PytestWarning(
"Value of environment variable {name} type should be str, but got "
"{value!r} (type: {type}); converted to str implicitly".format(
name=name, value=value, type=type(value).__name__
Expand Down
2 changes: 2 additions & 0 deletions src/pytest/__init__.py
Expand Up @@ -21,6 +21,7 @@
from _pytest.main import Session
from _pytest.mark import MARK_GEN as mark
from _pytest.mark import param
from _pytest.monkeypatch import MonkeyPatch
from _pytest.nodes import Collector
from _pytest.nodes import File
from _pytest.nodes import Item
Expand Down Expand Up @@ -76,6 +77,7 @@
"main",
"mark",
"Module",
"MonkeyPatch",
"Package",
"param",
"PytestAssertRewriteWarning",
Expand Down

0 comments on commit b6363de

Please sign in to comment.