mocker can not replace a object/module two times

Bug #700539 reported by Francisco Souza
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mocker
Invalid
Undecided
Gustavo Niemeyer

Bug Description

Mocker is unable to replace a object/module two times:

>>> import mocker
>>> m = mocker.Mocker()
>>> dt = m.replace('datetime.datetime')
>>> dt()
<mocker.Mock object at 0x859ea6c>
>>> m.result('my datetime')
>>> m.replay()
>>> from datetime import datetime
>>> datetime()
'my datetime'
>>> m.restore()
>>> from datetime import datetime
>>> datetime() # the original
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Required argument 'year' (pos 1) not found
>>> dt_new = m.replace('datetime.datetime') # replacing for the second time
>>> dt_new()
<mocker.Mock object at 0x859eecc>
>>> m.result('other datetime')
>>> m.replay()
>>> from datetime import datetime
>>> datetime()
'my datetime'
>>>

Tags: replace
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

The API is being used improperly:

    def restore(self):
        """Restore changes in the environment, and return to recording mode.

    def reset(self):
        """Reset the mocker state.

        This will restore environment changes, if currently in replay
        mode, and then remove all events previously recorded.
        """

Changed in mocker:
assignee: nobody → Gustavo Niemeyer (niemeyer)
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.