Skip to content

Commit cfb56e0

Browse files
committed
Set __module__ = "pytest" on most public types
It doesn't seem possible to cleanly set it on dataclasses and namedtuple types, so skipped these for now. Fix #13812.
1 parent 1d0c8a7 commit cfb56e0

File tree

18 files changed

+74
-0
lines changed

18 files changed

+74
-0
lines changed

src/_pytest/capture.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ class CaptureFixture(Generic[AnyStr]):
917917
"""Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
918918
:fixture:`capfd` and :fixture:`capfdbinary` fixtures."""
919919

920+
__module__ = "pytest"
921+
920922
def __init__(
921923
self,
922924
captureclass: type[CaptureBase[AnyStr]],

src/_pytest/config/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ class PytestPluginManager(PluginManager):
404404
* ``conftest.py`` loading during start-up.
405405
"""
406406

407+
__module__ = "pytest"
408+
407409
def __init__(self) -> None:
408410
from _pytest.assertion import DummyRewriteHook
409411
from _pytest.assertion import RewriteHook
@@ -982,6 +984,8 @@ class Config:
982984
invocation.
983985
"""
984986

987+
__module__ = "pytest"
988+
985989
@final
986990
@dataclasses.dataclass(frozen=True)
987991
class InvocationParams:

src/_pytest/config/argparsing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Parser:
3636
there's an error processing the command line arguments.
3737
"""
3838

39+
__module__ = "pytest"
40+
3941
prog: str | None = None
4042

4143
def __init__(
@@ -370,6 +372,8 @@ def __repr__(self) -> str:
370372
class OptionGroup:
371373
"""A group of options shown in its own section."""
372374

375+
__module__ = "pytest"
376+
373377
def __init__(
374378
self,
375379
name: str,

src/_pytest/doctest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def _get_runner(
249249

250250

251251
class DoctestItem(Item):
252+
__module__ = "pytest"
253+
252254
def __init__(
253255
self,
254256
name: str,

src/_pytest/fixtures.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ class FixtureRequest(abc.ABC):
366366
``param`` attribute in case the fixture is parametrized.
367367
"""
368368

369+
__module__ = "pytest"
370+
369371
def __init__(
370372
self,
371373
pyfuncitem: Function,
@@ -801,6 +803,8 @@ def addfinalizer(self, finalizer: Callable[[], object]) -> None:
801803
class FixtureLookupError(LookupError):
802804
"""Could not return a requested fixture (missing or invalid)."""
803805

806+
__module__ = "pytest"
807+
804808
def __init__(
805809
self, argname: str | None, request: FixtureRequest, msg: str | None = None
806810
) -> None:
@@ -964,6 +968,8 @@ class FixtureDef(Generic[FixtureValue]):
964968
considered public stable API.
965969
"""
966970

971+
__module__ = "pytest"
972+
967973
def __init__(
968974
self,
969975
config: Config,

src/_pytest/legacypath.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Testdir:
4747
to `legacy_path` objects as necessary.
4848
"""
4949

50+
__module__ = "pytest"
51+
5052
__test__ = False
5153

5254
CLOSE_STDIN: Final = Pytester.CLOSE_STDIN

src/_pytest/logging.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ def handleError(self, record: logging.LogRecord) -> None:
404404
class LogCaptureFixture:
405405
"""Provides access and control of log capturing."""
406406

407+
__module__ = "pytest"
408+
407409
def __init__(self, item: nodes.Node, *, _ispytest: bool = False) -> None:
408410
check_ispytest(_ispytest)
409411
self._item = item

src/_pytest/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ class Dir(nodes.Directory):
506506
collectors.
507507
"""
508508

509+
__module__ = "pytest"
510+
509511
@classmethod
510512
def from_parent( # type: ignore[override]
511513
cls,
@@ -552,6 +554,8 @@ class Session(nodes.Collector):
552554
``Session`` collects the initial paths given as arguments to pytest.
553555
"""
554556

557+
__module__ = "pytest"
558+
555559
Interrupted = Interrupted
556560
Failed = Failed
557561
# Set on the session by runner.pytest_sessionstart.

src/_pytest/mark/structures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ def test_function():
546546
applies a 'slowtest' :class:`Mark` on ``test_function``.
547547
"""
548548

549+
__module__ = "pytest"
550+
549551
# See TYPE_CHECKING above.
550552
if TYPE_CHECKING:
551553
skip: _SkipMarkDecorator

src/_pytest/monkeypatch.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ class MonkeyPatch:
129129
:meth:`undo` explicitly.
130130
"""
131131

132+
__module__ = "pytest"
133+
132134
def __init__(self) -> None:
133135
self._setattr: list[tuple[object, str, object]] = []
134136
self._setitem: list[tuple[Mapping[Any, Any], object, object]] = []

0 commit comments

Comments
 (0)