One function

create_autospec in testing-cabal/mock

The author described this change as gh-91803: Mock - fix error when using autospec methods with seal (#92213). It counts as a record because the check below fails on the code as it stood at 2b647d667 and passes on 4d3f1976a, with nothing else changed between the two runs.

Fix saved2022-12-28
Sharing licenceBSD-2-Clause · LICENSE.txt
Change size+1 0

What the code was meant to do, written into the code itself as a docstring

Create a mock object using another object as a spec. Attributes on the mock will use the corresponding attribute on the `spec` object as their spec. Functions or methods being mocked will have their arguments checked to check that they are called with the correct signature. If `spec_set` is True then attempting to set attributes that don't exist on the spec object will raise an `AttributeError`. If a class is used as a spec then the return value of the mock (the instance of the class) will have the same spec. You can use a class as the spec for an instance object by passing `instance=True`. The returned mock will only be callable if instances of the mock are callable. `create_autospec` will raise a `RuntimeError` if passed some common misspellings of the arguments autospec and spec_set. Pass the argument `unsafe` with the value True to disable that check. `create_autospec` also takes arbitrary keyword arguments that are passed to the constructor of the created mock.

The change

126126 _new_parent=parent,
127127 **kwargs)
128128 mock._mock_children[entry] = new
129+ new.return_value = child_klass()
129130 _check_signature(original, new, skipfirst=skipfirst)
130131
131132 # so functions created with _set_signature become instance attributes,

The check that tells the two apart

failpass·mock/tests/testsealable.py::TestSealable::test_seal_with_autospec

Check file mock/tests/testsealable.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 it2b647d6677fee5cd064b0aa2528cab061f6220bd
Broken version dated2022-12-28
Modulemock.mock
Units changedcreate_autospec
Fingerprint5d64453a9d398a01
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