]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109350: Fix outdated captured output in unittest.mock documentation (#109353)
authorEgil Martinsson <ragulpr@users.noreply.github.com>
Fri, 15 Sep 2023 18:25:16 +0000 (20:25 +0200)
committerGitHub <noreply@github.com>
Fri, 15 Sep 2023 18:25:16 +0000 (19:25 +0100)
Doc/library/unittest.mock-examples.rst
Doc/library/unittest.mock.rst

index 34f343ebacdbb76e90fb0cd11c8372309ac595d9..f2bdde80bdbd644f116bf939e0333b96c0ef50f6 100644 (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:
 
index 836fd42ab71c817b5c9473ccdd929fbfc5f1f093..1452276436099b2438f838932c987f3c58b9c2b3 100644 (file)
@@ -189,7 +189,7 @@ code if they are used incorrectly:
    >>> mock_function('wrong arguments')
    Traceback (most recent call last):
     ...
-   TypeError: <lambda>() takes exactly 3 arguments (1 given)
+   TypeError: missing a required argument: 'b'
 
 :func:`create_autospec` can also be used on classes, where it copies the signature of
 the ``__init__`` method, and on callable objects where it copies the signature of
@@ -315,6 +315,7 @@ the *new_callable* argument to :func:`patch`.
             Traceback (most recent call last):
             ...
             AssertionError: Expected 'method' to have been called once. Called 2 times.
+            Calls: [call(), call()].
 
         .. versionadded:: 3.6
 
@@ -342,7 +343,7 @@ the *new_callable* argument to :func:`patch`.
             Traceback (most recent call last):
               ...
             AssertionError: Expected 'mock' to be called once. Called 2 times.
-
+            Calls: [call('foo', bar='baz'), call('other', bar='values')].
 
     .. method:: assert_any_call(*args, **kwargs)
 
@@ -392,6 +393,7 @@ the *new_callable* argument to :func:`patch`.
             Traceback (most recent call last):
               ...
             AssertionError: Expected 'hello' to not have been called. Called 1 times.
+            Calls: [call()].
 
         .. versionadded:: 3.5
 
@@ -954,7 +956,7 @@ object::
         >>> asyncio.run(main())
         >>> mock.assert_awaited_once()
         >>> asyncio.run(main())
-        >>> mock.method.assert_awaited_once()
+        >>> mock.assert_awaited_once()
         Traceback (most recent call last):
         ...
         AssertionError: Expected mock to have been awaited once. Awaited 2 times.
@@ -972,7 +974,7 @@ object::
         >>> mock.assert_awaited_with('other')
         Traceback (most recent call last):
         ...
-        AssertionError: expected call not found.
+        AssertionError: expected await not found.
         Expected: mock('other')
         Actual: mock('foo', bar='bar')