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

Can't call mocked methods after create_autospec() and seal() #91803

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

Description

@dseomn

Bug report

The code below raises the error below. If I'm understanding the documentation for mock.seal correctly, it's supposed to prevent the creation of new attributes on the sealed mock, not prevent calls to existing methods, right?

fromunittestimportmockclassFoo:deffoo(self)->int:return0foo=mock.create_autospec(Foo,instance=True)mock.seal(foo)foo.foo()
Traceback (most recent call last):  File "/tmp/tmp.8toUu9Dy3T/foo.py", line 7, in <module>    foo.foo()  File "/usr/lib/python3.9/unittest/mock.py", line 1092, in __call__    return self._mock_call(*args, **kwargs)  File "/usr/lib/python3.9/unittest/mock.py", line 1096, in _mock_call    return self._execute_mock_call(*args, **kwargs)  File "/usr/lib/python3.9/unittest/mock.py", line 1168, in _execute_mock_call    return self.return_value  File "/usr/lib/python3.9/unittest/mock.py", line 630, in __getattr__    raise AttributeError("Mock object has no attribute %r" % name)AttributeError: Mock object has no attribute 'return_value'

Your environment

  • CPython versions tested on: 3.9.9
  • Operating system and architecture: Debian testing / amd64

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