Whole file
testing-cabal/mock
The author described this change as “Fix bug where a failure to create a nested patch could leave patches undone”. It counts as a record because the check below fails on the code as it stood at d12fa2c45 and passes on a5f50ae53, with nothing else changed between the two runs.
Projecttesting-cabal/mock
Fix saved2011-07-13
Sharing licenceBSD-2-Clause · LICENSE.txt
Change size+13 −11
What the code was meant to do, written into the code itself as a save note
Fix bug where a failure to create a nested patch could leave patches undone
The change
| 914 | 914 | def patched(*args, **keywargs): | |
| 915 | 915 | # don't use a with here (backwards compatability with Python 2.4) | |
| 916 | 916 | extra_args = [] | |
| 917 | - | for patching in patched.patchings: | |
| 918 | - | arg = patching.__enter__() | |
| 919 | - | if patching.new is DEFAULT: | |
| 920 | - | # arg will either be a mock or a dict | |
| 921 | - | if patching.attribute_name is not None: | |
| 922 | - | keywargs.update(arg) | |
| 923 | - | else: | |
| 924 | - | extra_args.append(arg) | |
| 925 | - | ||
| 926 | - | args += tuple(extra_args) | |
| 917 | + | entered_patchers = [] | |
| 927 | 918 | try: | |
| 919 | + | for patching in patched.patchings: | |
| 920 | + | arg = patching.__enter__() | |
| 921 | + | entered_patchers.append(patching) | |
| 922 | + | if patching.new is DEFAULT: | |
| 923 | + | # arg will either be a mock or a dict | |
| 924 | + | if patching.attribute_name is not None: | |
| 925 | + | keywargs.update(arg) | |
| 926 | + | else: | |
| 927 | + | extra_args.append(arg) | |
| 928 | + | ||
| 929 | + | args += tuple(extra_args) | |
| 928 | 930 | return func(*args, **keywargs) | |
| 929 | 931 | finally: | |
| 930 | - | for patching in reversed(patched.patchings): | |
| 932 | + | for patching in reversed(entered_patchers): | |
| 931 | 933 | patching.__exit__() | |
| 932 | 934 | ||
| 933 | 935 | patched.patchings = [self] |
The check that tells the two apart
fail→pass·tests/testpatch.py::PatchTest::test_nested_patch_failure
Check file 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 itd12fa2c455fea01d6e3bb0992f4675a56c4115d0
Broken version dated2011-07-13
Modulemock
Units changed_patch
Fingerprint46b70ba556ff43fd
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
- 2020-01-29_patch_object
- 2012-01-22_Call
- 2011-07-19Fix callargs call comparisons