Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AttributeError from stopping stopped patch which was started more than once #104745

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@Red4Ru

Description

@Red4Ru

Bug report

It seems, such bug appeared after4b222c9
Suppose we have initialized patch, than callstart more than once and than callstop more than once:

>>> from unittest import mock... class Foo:...     bar = None... patch = mock.patch.object(Foo, 'bar', 'x')>>> patch.start()'x'>>> patch.start()'x'>>> patch.stop()False>>> patch.stop()Traceback (most recent call last):  File "...", line ..., in runcode    coro = func()  File "<input>", line 1, in <module>  File "/usr/lib/python3.8/unittest/mock.py", line 1542, in stop    return self.__exit__(None, None, None)  File "/usr/lib/python3.8/unittest/mock.py", line 1508, in __exit__    if self.is_local and self.temp_original is not DEFAULT:AttributeError: '_patch' object has no attribute 'is_local'

But if we callstart only once, multiplestops won't cause such error.
For a first glance it is due tostop exceptingValueError on removing patch from_active_patches and ifValueError was not raised it proceeds assuming patch have attributeis_local.

Your environment

  • CPython versions tested on: Python 3.8
  • Operating system: Ubuntu
  • I think error exists in newer versions too

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp