replace not replacing random module

Bug #1293530 reported by Zalán Somogyváry
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mocker
New
Undecided
Unassigned

Bug Description

Hello!

I'm unable to replace the random module through mocker.replace('random') calls. I'm not sure if I have done something wrong but the mocker seems not to replace the random module with a proxy. A little code snippet to demonstrate:

randint_stub = mocker.replace('random.randint', passthrough=False)
randint_stub(ANY, ANY)
mocker.count(1)

If I do this I always get:
Unmet expectations:

=> random.randint(ANY, ANY)
 - Performed fewer times than expected.

Tags: random replace
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Try this...

import random

import mocker

mocker = mocker.Mocker()
random_mock = mocker.replace(random)
random_mock.randint(1, 5)

mocker.result(9)
mocker.replay()

random.randint(1, 5)

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.