Skip to content

Commit f848e01

Browse files
miss-islingtongpshead
authored andcommitted
bpo-47235: Note where a typo is intentional in code. (pythonGH-32348)
People keep popping up reporting these as typos in the docs despite being described as typos in the surrounding text. Hopefully a comment on the line itself makes it more obvious? Arguably some of the typo examples are not using the "right" typo as the "assret" one in particular is now detected by default due to how common it was in actual code. But I don't want to to typo chasing by changing these examples to be other not yet auto-detected typos as they still illustrate the point well enough. (cherry picked from commit ac1fb07) Co-authored-by: Gregory P. Smith <[email protected]>
1 parent 3239018 commit f848e01

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Doc/library/unittest.mock.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,7 @@ your assertion is gone:
25492549
25502550
>>> mock = Mock(name='Thing', return_value=None)
25512551
>>> mock(1, 2, 3)
2552-
>>> mock.assret_called_once_with(4, 5, 6)
2552+
>>> mock.assret_called_once_with(4, 5, 6) # Intentional typo!
25532553
25542554
Your tests can pass silently and incorrectly because of the typo.
25552555

@@ -2569,7 +2569,7 @@ attributes on the mock that exist on the real class:
25692569

25702570
>>> from urllib import request
25712571
>>> mock = Mock(spec=request.Request)
2572-
>>> mock.assret_called_with
2572+
>>> mock.assret_called_with # Intentional typo!
25732573
Traceback (most recent call last):
25742574
...
25752575
AttributeError: Mock object has no attribute 'assret_called_with'
@@ -2581,7 +2581,7 @@ with any methods on the mock:
25812581
25822582
>>> mock.has_data()
25832583
<mock.Mock object at 0x...>
2584-
>>> mock.has_data.assret_called_with()
2584+
>>> mock.has_data.assret_called_with() # Intentional typo!
25852585
25862586
Auto-speccing solves this problem. You can either pass ``autospec=True`` to
25872587
:func:`patch` / :func:`patch.object` or use the :func:`create_autospec` function to create a
@@ -2624,7 +2624,7 @@ any typos in our asserts will raise the correct error::
26242624

26252625
>>> req.add_header('spam', 'eggs')
26262626
<MagicMock name='request.Request().add_header()' id='...'>
2627-
>>> req.add_header.assret_called_with
2627+
>>> req.add_header.assret_called_with # Intentional typo!
26282628
Traceback (most recent call last):
26292629
...
26302630
AttributeError: Mock object has no attribute 'assret_called_with'

0 commit comments

Comments
 (0)