@@ -401,6 +401,8 @@ the *new_callable* argument to :func:`patch`.
401
401
402
402
The reset_mock method resets all the call attributes on a mock object:
403
403
404
+ .. doctest ::
405
+
404
406
>>> mock = Mock(return_value = None )
405
407
>>> mock(' hello' )
406
408
>>> mock.called
@@ -409,20 +411,41 @@ the *new_callable* argument to :func:`patch`.
409
411
>>> mock.called
410
412
False
411
413
412
- .. versionchanged :: 3.6
413
- Added two keyword-only arguments to the reset_mock function.
414
-
415
414
This can be useful where you want to make a series of assertions that
416
- reuse the same object. Note that :meth: `reset_mock ` *doesn't * clear the
415
+ reuse the same object.
416
+
417
+ *return_value * parameter when set to ``True `` resets :attr: `return_value `:
418
+
419
+ .. doctest ::
420
+
421
+ >>> mock = Mock(return_value = 5 )
422
+ >>> mock(' hello' )
423
+ 5
424
+ >>> mock.reset_mock(return_value = True )
425
+ >>> mock(' hello' ) # doctest: +ELLIPSIS
426
+ <Mock name='mock()' id='...'>
427
+
428
+ *side_effect * parameter when set to ``True `` resets :attr: `side_effect `:
429
+
430
+ .. doctest ::
431
+
432
+ >>> mock = Mock(side_effect = ValueError )
433
+ >>> mock(' hello' )
434
+ Traceback (most recent call last):
435
+ ...
436
+ ValueError
437
+ >>> mock.reset_mock(side_effect = True )
438
+ >>> mock(' hello' ) # doctest: +ELLIPSIS
439
+ <Mock name='mock()' id='...'>
440
+
441
+ Note that :meth: `reset_mock ` *doesn't * clear the
417
442
:attr: `return_value `, :attr: `side_effect ` or any child attributes you have
418
- set using normal assignment by default. In case you want to reset
419
- :attr: `return_value ` or :attr: `side_effect `, then pass the corresponding
420
- parameter as ``True ``. Child mocks and the return value mock
421
- (if any) are reset as well.
443
+ set using normal assignment by default.
422
444
423
- .. note :: *return_value*, and *side_effect* are keyword-only
424
- arguments.
445
+ Child mocks are reset as well.
425
446
447
+ .. versionchanged :: 3.6
448
+ Added two keyword-only arguments to the reset_mock function.
426
449
427
450
.. method :: mock_add_spec(spec, spec_set=False)
428
451
0 commit comments