Skip to content
Merged
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 docs/adr/0001-expose-installs-into-modules-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rejecting an empty call and raising on a name two groups both claim, and install
module. The decision half already lives in the private, pure `_collect_fixtures`; the recurring
proposal is to extract the install half too, wrapping the `name -> provider` mapping in a
`FixtureSet` exposing `.install(into=...)`. We will not, because a seam needs two adapters and the
only install targets are the caller's module, located via `inspect.stack()`, and an explicit
only install targets are the caller's module, located through the calling frame, and an explicit
`module=`, both `types.ModuleType`, which is one adapter exercised with two instances. Deleting a
`FixtureSet` would bring back no complexity, since its `setattr` loop simply inlines, so the install
step stays that loop and the public surface stays at `expose` and `modern_di_fixture`. A genuinely
Expand Down
6 changes: 3 additions & 3 deletions modern_di_pytest/factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import sys
import types
import typing

Expand Down Expand Up @@ -129,7 +130,7 @@ def expose(
A provider with this name raises ``ValueError``.
pytest_scope: pytest fixture scope applied to every generated fixture.
module: Module to install fixtures onto. Defaults to the caller's module
(located via ``inspect.stack()``).
(located via the calling frame).

Example (in ``conftest.py``)::

Expand All @@ -144,8 +145,7 @@ def expose(
"""
_require_groups(groups)
if module is None:
frame = inspect.stack()[1].frame
module = inspect.getmodule(frame)
module = inspect.getmodule(sys._getframe(1)) # noqa: SLF001
if module is None:
msg = "expose() could not determine the caller module; pass module=... explicitly."
raise RuntimeError(msg)
Expand Down
Loading