Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
1d31273
refactor: Remove lazy loading from PyobjMixin and simplify module imp…
RonnyPfannschmidt Sep 24, 2025
a10bc95
WIP: Refactor PyobjMixin to remove lazy loading and unify instance ma…
RonnyPfannschmidt Sep 24, 2025
ac9f29d
Refactor PyobjMixin for eager object passing and fix marker collection
RonnyPfannschmidt Sep 25, 2025
6a896af
Fix mypy errors from PyobjMixin refactoring
RonnyPfannschmidt Sep 25, 2025
2fd2803
Fix DefinitionMock to use proper __init__ instead of dataclass
RonnyPfannschmidt Sep 25, 2025
b28ea37
Fix test_class_from_parent to use cooperative constructor
RonnyPfannschmidt Sep 25, 2025
80e4d72
Add filterwarnings marker to TestConftestValueAccessGlobal
RonnyPfannschmidt Sep 25, 2025
cc8faa1
Implement lazy loading for Module.obj using cached property
RonnyPfannschmidt Sep 25, 2025
8239cb3
Fix test_pytest_pycollect_makeitem to pass callobj to Function.from_p…
RonnyPfannschmidt Sep 25, 2025
ccd34f2
Make Function.from_parent auto-resolve callobj from parent
RonnyPfannschmidt Sep 25, 2025
e1ab6f2
Fix setup_method/teardown_method to receive bound methods
RonnyPfannschmidt Sep 25, 2025
e7a57cf
Summary: PyobjMixin refactoring progress
RonnyPfannschmidt Sep 25, 2025
16c9411
Fix fixture handling for class/static methods and add Function.instan…
RonnyPfannschmidt Sep 25, 2025
11c1b1b
WIP: Messy intermediate state - opt-in function definition refactoring
RonnyPfannschmidt Sep 25, 2025
6d86679
one more intermediate, im done here omg
RonnyPfannschmidt Sep 25, 2025
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
10 changes: 10 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(grep:*)",
"Bash(uv run pytest:*)"
],
"deny": []
},
"outputStyle": "default"
}
11 changes: 8 additions & 3 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,15 @@ def getfuncargnames(
if not any(p.kind is Parameter.POSITIONAL_ONLY for p in parameters) and (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Invert any/all to simplify comparisons (invert-any-all)

Suggested change
if not any(p.kind is Parameter.POSITIONAL_ONLY for p in parameters) and (
if all(p.kind is not Parameter.POSITIONAL_ONLY for p in parameters) and (

# Not using `getattr` because we don't want to resolve the staticmethod.
# Not using `cls.__dict__` because we want to check the entire MRO.
cls
and not isinstance(
inspect.getattr_static(cls, name, default=None), staticmethod
(
cls
and not isinstance(
inspect.getattr_static(cls, name, default=None), staticmethod
)
)
or
# Handle bound methods (e.g., from plugin instances)
hasattr(function, "__self__")
):
arg_names = arg_names[1:]
# Remove any names that will be replaced with mocks.
Expand Down
31 changes: 21 additions & 10 deletions src/_pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def pytest_collect_file(
if config.option.doctestmodules and not any(
(_is_setup_py(file_path), _is_main_py(file_path))
):
return DoctestModule.from_parent(parent, path=file_path)
return DoctestModule.from_parent(parent, path=file_path) # type: ignore[no-any-return]
elif _is_doctest(config, file_path, parent):
return DoctestTextfile.from_parent(parent, path=file_path)
return DoctestTextfile.from_parent(parent, path=file_path) # type: ignore[no-any-return]
return None


Expand Down Expand Up @@ -418,7 +418,7 @@ def _get_continue_on_failure(config: Config) -> bool:


class DoctestTextfile(Module):
obj = None
obj: None = None # type: ignore[assignment]

def collect(self) -> Iterable[DoctestItem]:
import doctest
Expand Down Expand Up @@ -544,13 +544,24 @@ def _from_module(self, module, object):
# Type ignored because this is a private function.
return super()._from_module(module, object) # type: ignore[misc]

try:
module = self.obj
except Collector.CollectError:
if self.config.getvalue("doctest_ignore_import_errors"):
skip(f"unable to import module {self.path!r}")
else:
raise
# Ensure the module is imported (similar to Module.collect)
if not hasattr(self, "obj") or self.obj is None:
from _pytest.python import importtestmodule

try:
self.obj = importtestmodule(self.path, self.config)
# Extract markers from the module after importing
if self._ALLOW_MARKERS:
from _pytest.mark.structures import get_unpacked_marks

self.own_markers.extend(get_unpacked_marks(self.obj))
except Collector.CollectError:
if self.config.getvalue("doctest_ignore_import_errors"):
skip(f"unable to import module {self.path!r}")
else:
raise

module = self.obj

# While doctests currently don't support fixtures directly, we still
# need to pick up autouse fixtures.
Expand Down
Loading
Loading