gh-109350: Fix outdated captured output in unittest.mock documentation (#109353)

This commit is contained in:
Egil Martinsson 2023-09-15 20:25:16 +02:00 committed by GitHub
parent 92ed7e4df1
commit 3d881453d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View file

@ -339,7 +339,7 @@ instantiate the class in those tests.
>>> mock.old_method()
Traceback (most recent call last):
...
AttributeError: object has no attribute 'old_method'
AttributeError: Mock object has no attribute 'old_method'. Did you mean: 'class_method'?
Using a specification also enables a smarter matching of calls made to the
mock, regardless of whether some parameters were passed as positional or
@ -798,7 +798,8 @@ If your mock is only being called once you can use the
>>> mock.foo_bar.assert_called_once_with('baz', spam='eggs')
Traceback (most recent call last):
...
AssertionError: Expected to be called once. Called 2 times.
AssertionError: Expected 'foo_bar' to be called once. Called 2 times.
Calls: [call('baz', spam='eggs'), call()].
Both ``assert_called_with`` and ``assert_called_once_with`` make assertions about
the *most recent* call. If your mock is going to be called several times, and
@ -927,8 +928,9 @@ Here's an example implementation:
>>> c.assert_called_with(arg)
Traceback (most recent call last):
...
AssertionError: Expected call: mock({1})
Actual call: mock(set())
AssertionError: expected call not found.
Expected: mock({1})
Actual: mock(set())
>>> c.foo
<CopyingMock name='mock.foo' id='...'>
@ -1292,8 +1294,9 @@ sufficient:
>>> mock.assert_called_with(Foo(1, 2))
Traceback (most recent call last):
...
AssertionError: Expected: call(<__main__.Foo object at 0x...>)
Actual call: call(<__main__.Foo object at 0x...>)
AssertionError: expected call not found.
Expected: mock(<__main__.Foo object at 0x...>)
Actual: mock(<__main__.Foo object at 0x...>)
A comparison function for our ``Foo`` class might look something like this: