Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctest collection of functools.cached_property objects. #11317

Merged
merged 4 commits into from Sep 7, 2023

Conversation

tjsmart
Copy link
Contributor

@tjsmart tjsmart commented Aug 16, 2023

I'll be first to admit that the proposed solution is very hacky but felt inspired by some adjacent code to do things this way. Suggestions for improvement are welcomed. 馃檪

closes #11237


# Type ignored because this is a private function.
return super()._from_module(module, object) # type: ignore[misc]

if self.path.name == "conftest.py":
Copy link
Member

Choose a reason for hiding this comment

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

At first glance this Looks like this ought to be a extra elif next two the property handling of the mock class with the hack's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes perfect sense. I'm going to wait on the cpython fix to be implemented before pushing this forward. It might offer some additional insights.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

python/cpython#107996 has been merged. I think the original idea of the PR is still the way to fix this issue. However, I did move the method override of _from_module to the pre-existing DocTestFinder subclass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we rename MockAwareDocTestFinder?

src/_pytest/doctest.py Outdated Show resolved Hide resolved
src/_pytest/doctest.py Outdated Show resolved Hide resolved
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

LGTM! I'll let @RonnyPfannschmidt do the merge.

@nicoddemus
Copy link
Member

Should we backport this?

@RonnyPfannschmidt
Copy link
Member

I'm under the impression we should

@nicoddemus
Copy link
Member

Can you review/merge and backport then @RonnyPfannschmidt ? Or would you like me to go ahead with it?

@RonnyPfannschmidt
Copy link
Member

I won't be able to get to it before next week earliest

@RonnyPfannschmidt RonnyPfannschmidt added needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch backport 7.4.x labels Sep 7, 2023
@RonnyPfannschmidt RonnyPfannschmidt merged commit e787d2e into pytest-dev:main Sep 7, 2023
27 checks passed
@RonnyPfannschmidt
Copy link
Member

@nicoddemus any idea why the back-porting workflow failed?

@nicoddemus
Copy link
Member

@nicoddemus any idea why the back-porting workflow failed?

We need to add the backport 7.4.x label after the PR is merged.

@RonnyPfannschmidt
Copy link
Member

i see, can we also trigger it on a merge if there is the label applied?

@nicoddemus
Copy link
Member

We did consider it at the time, but IIRC it would complicate the action significantly and nobody wanted to tackle that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@cached_property is not checked for doctests
4 participants