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 — unittest.mock.patch with autospec doesn't hold for classmethods nor staticmethods · Issue #102978 · python/cpython Closed Closed Copy link Labels stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportUsing Example: from unittest.mock import patch import pytest class Foo: def foo(self): pass @staticmethod def bar(): pass @classmethod def baz(cls): pass @pytest.mark.parametrize("method", ["foo", "bar", "baz"]) def test_foo(method: str): with patch.object(Foo, method, autospec=True): getattr(Foo(), method)(5) The only subtest that fails is If you prefer not to use with patch.object(Foo, "foo", autospec=True): try: Foo().foo(5) except TypeError: print("Correctly raises on foo") else: print("Incorrectly does not raise with foo") with patch.object(Foo, "bar", autospec=True): try: Foo().bar(5) except TypeError: print("Correctly raises on bar") else: print("Incorrectly does not raise with bar") with patch.object(Foo, "baz", autospec=True): try: Foo().baz(5) except TypeError: print("Correctly raises on baz") else: print("Incorrectly does not raise with baz") This has output: Your environment
Linked PRsActivity
MetadataMetadataAssigneesLabelsstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-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. |