Merge pull request #11326 from DetachHead/DetachHead-patch-1
use `if not TYPE_CHECKING` on `pytest.__getattr__` to prevent type checkers from using it
This commit is contained in:
commit
03832fa31e
|
@ -1,5 +1,7 @@
|
||||||
# PYTHON_ARGCOMPLETE_OK
|
# PYTHON_ARGCOMPLETE_OK
|
||||||
"""pytest: unit and functional testing with Python."""
|
"""pytest: unit and functional testing with Python."""
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from _pytest import __version__
|
from _pytest import __version__
|
||||||
from _pytest import version_tuple
|
from _pytest import version_tuple
|
||||||
from _pytest._code import ExceptionInfo
|
from _pytest._code import ExceptionInfo
|
||||||
|
@ -165,11 +167,12 @@ __all__ = [
|
||||||
"yield_fixture",
|
"yield_fixture",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not TYPE_CHECKING:
|
||||||
|
|
||||||
def __getattr__(name: str) -> object:
|
def __getattr__(name: str) -> object:
|
||||||
if name == "Instance":
|
if name == "Instance":
|
||||||
# The import emits a deprecation warning.
|
# The import emits a deprecation warning.
|
||||||
from _pytest.python import Instance
|
from _pytest.python import Instance
|
||||||
|
|
||||||
return Instance
|
return Instance
|
||||||
raise AttributeError(f"module {__name__} has no attribute {name}")
|
raise AttributeError(f"module {__name__} has no attribute {name}")
|
||||||
|
|
|
@ -272,7 +272,7 @@ def test_importing_instance_is_deprecated(pytester: Pytester) -> None:
|
||||||
pytest.PytestDeprecationWarning,
|
pytest.PytestDeprecationWarning,
|
||||||
match=re.escape("The pytest.Instance collector type is deprecated"),
|
match=re.escape("The pytest.Instance collector type is deprecated"),
|
||||||
):
|
):
|
||||||
pytest.Instance
|
pytest.Instance # type:ignore[attr-defined]
|
||||||
|
|
||||||
with pytest.warns(
|
with pytest.warns(
|
||||||
pytest.PytestDeprecationWarning,
|
pytest.PytestDeprecationWarning,
|
||||||
|
|
Loading…
Reference in New Issue