One function
_patch_object in testing-cabal/mock
The author described this change as “bpo-38669: patch.object now raises a helpful error (GH17034)”. It counts as a record because the check below fails on the code as it stood at a6768e641 and passes on c000fff5b, with nothing else changed between the two runs.
Projecttesting-cabal/mock
Fix saved2020-01-29
Sharing licenceBSD-2-Clause · LICENSE.txt
Change size+4 −0
What the code was meant to do, written into the code itself as a docstring
patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. Like `patch`, `patch.object` takes arbitrary keyword arguments for configuring the mock object it creates. When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` for choosing which methods to wrap.
The change
| 16 | 16 | When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` | |
| 17 | 17 | for choosing which methods to wrap. | |
| 18 | 18 | """ | |
| 19 | + | if type(target) is str: | |
| 20 | + | raise TypeError( | |
| 21 | + | f"{target!r} must be the actual object to be patched, not a str" | |
| 22 | + | ) | |
| 19 | 23 | getter = lambda: target | |
| 20 | 24 | return _patch( | |
| 21 | 25 | getter, attribute, new, spec, create, |
The check that tells the two apart
fail→pass·mock/tests/testpatch.py::PatchTest::test_patchobject_with_string_as_target
Check file mock/tests/testpatch.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before ita6768e64120cd6c963035044e9d70fb85f2dabc0
Broken version dated2020-01-29
Modulemock.mock
Units changed_patch_object
Fingerprinte8da7c498902bdad
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in testing-cabal/mock
- 2023-04-16_get_signature_object
- 2022-12-28create_autospec
- 2020-01-29_patch_dict
- 2012-01-22_Call
- 2011-07-19Fix callargs call comparisons
- 2011-07-13Fix bug where a failure to create a nested patch could leave patches undone