@@ -2584,40 +2584,16 @@ called incorrectly.
25842584
25852585Before I explain how auto-speccing works, here's why it is needed.
25862586
2587- :class: `Mock ` is a very powerful and flexible object, but it suffers from two flaws
2588- when used to mock out objects from a system under test. One of these flaws is
2589- specific to the :class: `Mock ` api and the other is a more general problem with using
2590- mock objects.
2591-
2592- First the problem specific to :class: `Mock `. :class: `Mock ` has two assert methods that are
2593- extremely handy: :meth: `~Mock.assert_called_with ` and
2594- :meth: `~Mock.assert_called_once_with `.
2595-
2596- >>> mock = Mock(name = ' Thing' , return_value = None )
2597- >>> mock(1 , 2 , 3 )
2598- >>> mock.assert_called_once_with(1 , 2 , 3 )
2599- >>> mock(1 , 2 , 3 )
2600- >>> mock.assert_called_once_with(1 , 2 , 3 )
2601- Traceback (most recent call last):
2602- ...
2603- AssertionError: Expected 'mock' to be called once. Called 2 times.
2604-
2605- Because mocks auto-create attributes on demand, and allow you to call them
2606- with arbitrary arguments, if you misspell one of these assert methods then
2607- your assertion is gone:
2608-
2609- .. code-block :: pycon
2610-
2611- >>> mock = Mock(name='Thing', return_value=None)
2612- >>> mock(1, 2, 3)
2613- >>> mock.assret_called_once_with(4, 5, 6) # Intentional typo!
2587+ :class: `Mock ` is a very powerful and flexible object, but it suffers from a flaw which
2588+ is general to mocking. If you refactor some of your code, rename members and so on, any
2589+ tests for code that is still using the *old api * but uses mocks instead of the real
2590+ objects will still pass. This means your tests can all pass even though your code is
2591+ broken.
26142592
2615- Your tests can pass silently and incorrectly because of the typo.
2593+ .. versionchanged :: 3.5
26162594
2617- The second issue is more general to mocking. If you refactor some of your
2618- code, rename members and so on, any tests for code that is still using the
2619- *old api * but uses mocks instead of the real objects will still pass. This
2620- means your tests can all pass even though your code is broken.
2595+ Before 3.5, tests with a typo in the word assert would silently pass when they should
2596+ raise an error. You can still achieve this behavior by passing ``unsafe=True `` to Mock.
26212597
26222598Note that this is another reason why you need integration tests as well as
26232599unit tests. Testing everything in isolation is all fine and dandy, but if you
0 commit comments