GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Mock spec not respected for attributes prefixed with assert · Issue #100739 · python/cpython Closed Labels type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportExample: from unittest.mock import Mock class Foo: def assert_something(self): pass m = Mock(spec=Foo) m.assert_something() An exception is raised: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/cklein/github/cklein/cpython/Lib/unittest/mock.py", line 657, in __getattr__ raise AttributeError( AttributeError: 'assert_something' is not a valid assertion. Use a spec for the mock if 'assert_something' is meant to be an attribute. Python 3.9 and lower: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/unittest/mock.py", line 635, in __getattr__ raise AttributeError("Attributes cannot start with 'assert' " AttributeError: Attributes cannot start with 'assert' or 'assret' The error message suggests that accessing attributes with prefix "assert_" should work when using a spec. See cklein@735ffc4 for a possible fix Your environment
Linked PRsActivity
MetadataMetadataAssigneesLabelstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |