Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/en/how-to/capture-warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ The :fixture:`recwarn` fixture will record warnings for the whole function:
assert w.lineno

Both the :fixture:`recwarn` fixture and the :func:`pytest.warns` context manager return the same interface for recorded
warnings: a :class:`~_pytest.recwarn.WarningsRecorder` instance. To view the recorded warnings, you can
warnings: a :class:`~pytest.WarningsRecorder` instance. To view the recorded warnings, you can
iterate over this instance, call ``len`` on it to get the number of recorded
warnings, or index into it to get a particular recorded warning.

Expand Down
4 changes: 2 additions & 2 deletions doc/en/how-to/fixtures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ could handle it by adding something like this to the test file:
Fixtures can introspect the requesting test context
-------------------------------------------------------------

Fixture functions can accept the :py:class:`request <_pytest.fixtures.FixtureRequest>` object
Fixture functions can accept the :py:class:`request <pytest.FixtureRequest>` object
to introspect the "requesting" test function, class or module context.
Further extending the previous ``smtp_connection`` fixture example, let's
read an optional server URL from the test module which uses our fixture:
Expand Down Expand Up @@ -1180,7 +1180,7 @@ from the module namespace.
Using markers to pass data to fixtures
-------------------------------------------------------------

Using the :py:class:`request <_pytest.fixtures.FixtureRequest>` object, a fixture can also access
Using the :py:class:`request <pytest.FixtureRequest>` object, a fixture can also access
markers which are applied to a test function. This can be useful to pass data
into a fixture from a test:

Expand Down
3 changes: 1 addition & 2 deletions doc/en/how-to/writing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,4 @@ in our ``pytest.ini`` to tell pytest where to look for example files.
============================ 2 passed in 0.12s =============================

For more information about the result object that ``runpytest()`` returns, and
the methods that it provides please check out the :py:class:`RunResult
<_pytest.pytester.RunResult>` documentation.
the methods that it provides please check out the :class:`~pytest.RunResult` documentation.
2 changes: 2 additions & 0 deletions src/_pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ class CaptureFixture(Generic[AnyStr]):
"""Object returned by the :fixture:`capsys`, :fixture:`capsysbinary`,
:fixture:`capfd` and :fixture:`capfdbinary` fixtures."""

__module__ = "pytest"

def __init__(
self,
captureclass: type[CaptureBase[AnyStr]],
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ class PytestPluginManager(PluginManager):
* ``conftest.py`` loading during start-up.
"""

__module__ = "pytest"

def __init__(self) -> None:
from _pytest.assertion import DummyRewriteHook
from _pytest.assertion import RewriteHook
Expand Down Expand Up @@ -981,6 +983,8 @@ class Config:
invocation.
"""

__module__ = "pytest"

@final
@dataclasses.dataclass(frozen=True)
class InvocationParams:
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/config/argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Parser:
there's an error processing the command line arguments.
"""

__module__ = "pytest"

prog: str | None = None

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

__module__ = "pytest"

def __init__(
self,
name: str,
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def _get_runner(


class DoctestItem(Item):
__module__ = "pytest"

def __init__(
self,
name: str,
Expand Down
6 changes: 6 additions & 0 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ class FixtureRequest(abc.ABC):
``param`` attribute in case the fixture is parametrized.
"""

__module__ = "pytest"

def __init__(
self,
pyfuncitem: Function,
Expand Down Expand Up @@ -801,6 +803,8 @@ def addfinalizer(self, finalizer: Callable[[], object]) -> None:
class FixtureLookupError(LookupError):
"""Could not return a requested fixture (missing or invalid)."""

__module__ = "pytest"

def __init__(
self, argname: str | None, request: FixtureRequest, msg: str | None = None
) -> None:
Expand Down Expand Up @@ -964,6 +968,8 @@ class FixtureDef(Generic[FixtureValue]):
considered public stable API.
"""

__module__ = "pytest"

def __init__(
self,
config: Config,
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/legacypath.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Testdir:
to `legacy_path` objects as necessary.
"""

__module__ = "pytest"

__test__ = False

CLOSE_STDIN: Final = Pytester.CLOSE_STDIN
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def handleError(self, record: logging.LogRecord) -> None:
class LogCaptureFixture:
"""Provides access and control of log capturing."""

__module__ = "pytest"

def __init__(self, item: nodes.Node, *, _ispytest: bool = False) -> None:
check_ispytest(_ispytest)
self._item = item
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ class Dir(nodes.Directory):
collectors.
"""

__module__ = "pytest"

@classmethod
def from_parent( # type: ignore[override]
cls,
Expand Down Expand Up @@ -552,6 +554,8 @@ class Session(nodes.Collector):
``Session`` collects the initial paths given as arguments to pytest.
"""

__module__ = "pytest"

Interrupted = Interrupted
Failed = Failed
# Set on the session by runner.pytest_sessionstart.
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ def test_function():
applies a 'slowtest' :class:`Mark` on ``test_function``.
"""

__module__ = "pytest"

# See TYPE_CHECKING above.
if TYPE_CHECKING:
skip: _SkipMarkDecorator
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class MonkeyPatch:
:meth:`undo` explicitly.
"""

__module__ = "pytest"

def __init__(self) -> None:
self._setattr: list[tuple[object, str, object]] = []
self._setitem: list[tuple[Mapping[Any, Any], object, object]] = []
Expand Down
12 changes: 10 additions & 2 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def _create(cls: type[_T], *k, **kw) -> _T:


class Node(abc.ABC, metaclass=NodeMeta):
r"""Base class of :class:`Collector` and :class:`Item`, the components of
the test collection tree.
r"""Base class of :class:`~pytest.Collector` and :class:`~pytest.Item`,
the components of the test collection tree.

``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the
leaf nodes.
Expand Down Expand Up @@ -503,6 +503,8 @@ class Collector(Node, abc.ABC):
the collection tree.
"""

__module__ = "pytest"

class CollectError(Exception):
"""An error during collection, contains a custom message."""

Expand Down Expand Up @@ -633,6 +635,8 @@ class File(FSCollector, abc.ABC):
:ref:`non-python tests`.
"""

__module__ = "pytest"


class Directory(FSCollector, abc.ABC):
"""Base class for collecting files from a directory.
Expand All @@ -651,13 +655,17 @@ class Directory(FSCollector, abc.ABC):
:ref:`custom directory collectors`.
"""

__module__ = "pytest"


class Item(Node, abc.ABC):
"""Base class of all test invocation items.

Note that for a single function there might be multiple test invocation items.
"""

__module__ = "pytest"

nextitem = None

def __init__(
Expand Down
12 changes: 11 additions & 1 deletion src/_pytest/pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ class RecordedHookCall:
assert calls[0].item is an_item
"""

__module__ = "pytest"

def __init__(self, name: str, kwargs) -> None:
self.__dict__.update(kwargs)
self._name = name
Expand All @@ -255,6 +257,8 @@ class HookRecorder:
before propagating the normal calls.
"""

__module__ = "pytest"

def __init__(
self, pluginmanager: PytestPluginManager, *, _ispytest: bool = False
) -> None:
Expand Down Expand Up @@ -518,6 +522,8 @@ def _config_for_test() -> Generator[Config]:
class RunResult:
"""The result of running a command from :class:`~pytest.Pytester`."""

__module__ = "pytest"

def __init__(
self,
ret: int | ExitCode,
Expand Down Expand Up @@ -655,6 +661,8 @@ class Pytester:
the current working directory to :attr:`path` and environment variables during initialization.
"""

__module__ = "pytest"

__test__ = False

CLOSE_STDIN: Final = NOTSET
Expand Down Expand Up @@ -1221,7 +1229,7 @@ def parseconfig(self, *args: str | os.PathLike[str]) -> Config:
"""Return a new pytest :class:`pytest.Config` instance from given
commandline args.

This invokes the pytest bootstrapping code in _pytest.config to create a
This invokes the pytest bootstrapping code to create a
new :py:class:`pytest.PytestPluginManager` and call the
:hook:`pytest_cmdline_parse` hook to create a new :class:`pytest.Config`
instance.
Expand Down Expand Up @@ -1565,6 +1573,8 @@ class LineMatcher:
``text.splitlines()``.
"""

__module__ = "pytest"

def __init__(self, lines: list[str]) -> None:
self.lines = lines
self._log_output: list[str] = []
Expand Down
10 changes: 10 additions & 0 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ def importtestmodule(
class Module(nodes.File, PyCollector):
"""Collector for test classes and functions in a Python module."""

__module__ = "pytest"

def _getobj(self):
return importtestmodule(self.path, self.config)

Expand Down Expand Up @@ -642,6 +644,8 @@ class Package(nodes.Directory):
Now inherits from :class:`~pytest.Directory`.
"""

__module__ = "pytest"

def __init__(
self,
fspath: LEGACY_PATH | None,
Expand Down Expand Up @@ -736,6 +740,8 @@ def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> object | N
class Class(PyCollector):
"""Collector for test methods (and nested classes) in a Python class."""

__module__ = "pytest"

@classmethod
def from_parent(cls, parent, *, name, obj=None, **kw) -> Self: # type: ignore[override]
"""The public constructor."""
Expand Down Expand Up @@ -1125,6 +1131,8 @@ class Metafunc:
test function is defined.
"""

__module__ = "pytest"

def __init__(
self,
definition: FunctionDefinition,
Expand Down Expand Up @@ -1566,6 +1574,8 @@ class Function(PyobjMixin, nodes.Item):
(``my_func[my_param]``).
"""

__module__ = "pytest"

# Disable since functions handle it themselves.
_ALLOW_MARKERS = False

Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ class RaisesExc(AbstractRaises[BaseExcT_co_default]):
...
"""

__module__ = "pytest"

# Trio bundled hypothesis monkeypatching, we will probably instead assume that
# hypothesis will handle that in their pytest plugin by the time this is released.
# Alternatively we could add a version of get_pretty_function_description ourselves
Expand Down Expand Up @@ -843,6 +845,8 @@ class RaisesGroup(AbstractRaises[BaseExceptionGroup[BaseExcT_co]]):
monkeypatch this output to provide shorter & more readable repr's.
"""

__module__ = "pytest"

# allow_unwrapped=True requires: singular exception, exception not being
# RaisesGroup instance, match is None, check is None
@overload
Expand Down
4 changes: 3 additions & 1 deletion src/_pytest/recwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

@fixture
def recwarn() -> Generator[WarningsRecorder]:
"""Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions.
"""Return a :class:`~pytest.WarningsRecorder` instance that records all warnings emitted by test functions.

See :ref:`warnings` for information on warning categories.
"""
Expand Down Expand Up @@ -180,6 +180,8 @@ class WarningsRecorder(warnings.catch_warnings):

"""

__module__ = "pytest"

def __init__(self, *, _ispytest: bool = False) -> None:
check_ispytest(_ispytest)
super().__init__(record=True)
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class TestReport(BaseReport):
Reports can contain arbitrary extra attributes.
"""

__module__ = "pytest"

__test__ = False

# Defined by skipping plugin.
Expand Down Expand Up @@ -403,6 +405,8 @@ class CollectReport(BaseReport):
Reports can contain arbitrary extra attributes.
"""

__module__ = "pytest"

when = "collect"

def __init__(
Expand Down
4 changes: 4 additions & 0 deletions src/_pytest/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class StashKey(Generic[T]):
.. versionadded:: 7.0
"""

__module__ = "pytest"

__slots__ = ()


Expand Down Expand Up @@ -67,6 +69,8 @@ class Stash:
.. versionadded:: 7.0
"""

__module__ = "pytest"

__slots__ = ("_storage",)

def __init__(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ def get_location(self, config: Config) -> str | None:

@final
class TerminalReporter:
__module__ = "pytest"

def __init__(self, config: Config, file: TextIO | None = None) -> None:
import _pytest.config

Expand Down