79200446

Date: 2024-11-18 15:11:50
Score: 0.5
Natty:
Report link

As @chepner mentioned there is only one module random to patch it is wrong, maybe you can update your code like below that way your issue should be resolved. let me know if issue still seen

modul1.py:

from random import random

def function():
    return random()

modul2.py:

from random import random

def function():
    return random()

The unit_test:

def test_function():
    with mock.patch('modul1.random', return_value=1), \
         mock.patch('modul2.random', return_value=0):
        val1 = modul1.function()
        val2 = modul2.function()
        assert not val1 == val2
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @chepner
  • Low reputation (0.5):
Posted by: justTesting