-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError from stopping stopped patch which was started more than once #104745
Comments
A couple of the |
As I can see, before 4b222c9 there was a check if attribute |
|
I have also stumbled upon this error. But in a little bit different use case. It was relatively hard to investigate as patch decorator was failing within one method and it also involved timing. Although I used threads and I agree it is dangerous path. Here I created simple testcase using unittest to show the issue:
What happens here is that this test will fail with following (Python 3.11):
Although using threads with tests and using patching is with warning attached, it is quite cumbersome to understand why such error can happen. By reading the unittest/mock.py and it's patch exit convention to delete attributes like self.local, self.target and others, one can start to suspect the thread problem to be the issue. |
i started having a look at this. but after reading the code and experimenting a bit i wonder if the bug is allowing |
I think it would be good to do this together with the implementation of the |
#126649) Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object. --------- Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…ping it (pythonGH-126649) Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object. --------- (cherry picked from commit 1e40c5b) Co-authored-by: Red4Ru <[email protected]> Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…ping it (pythonGH-126649) Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object. --------- (cherry picked from commit 1e40c5b) Co-authored-by: Red4Ru <[email protected]> Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…pping it (GH-126649) (#126773) gh-104745: Limit starting a patcher more than once without stopping it (GH-126649) Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object. --------- (cherry picked from commit 1e40c5b) Co-authored-by: Red4Ru <[email protected]> Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
…pping it (GH-126649) (#126772) gh-104745: Limit starting a patcher more than once without stopping it (GH-126649) Previously, this would cause an `AttributeError` if the patch stopped more than once after this, and would also disrupt the original patched object. --------- (cherry picked from commit 1e40c5b) Co-authored-by: Red4Ru <[email protected]> Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
I think the issue can be closed now |
Bug report
It seems, such bug appeared after 4b222c9
Suppose we have initialized patch, than call
start
more than once and than callstop
more than once:But if we call
start
only once, multiplestop
s won't cause such error.For a first glance it is due to
stop
exceptingValueError
on removing patch from_active_patches
and ifValueError
was not raised it proceeds assuming patch have attributeis_local
.Your environment
Linked PRs
The text was updated successfully, but these errors were encountered: