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.

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

914914 def patched(*args, **keywargs):
915915 # don't use a with here (backwards compatability with Python 2.4)
916916 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 = []
927918 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)
928930 return func(*args, **keywargs)
929931 finally:
930- for patching in reversed(patched.patchings):
932+ for patching in reversed(entered_patchers):
931933 patching.__exit__()
932934
933935 patched.patchings = [self]

The check that tells the two apart

failpass·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