0

I have a module ex which has multiple attributes and another module that uses these attributes like this

import ex
def use_ex(attr):
    z = getattr(ex,attr)
    #Do something with z

In my test file, I mock the ex as I cannot import it in the test environment.

sys.modules['ex'] = Mock()

How do I specify the return_value of ex.attr when I write the test for use_ex?

1 Answers1

-1

You can specify mock return values like this :

return_value = whatyouwant
my_mock = Mock()
my_mock.return_value = return_value
sys.modules['ex'] = my_mock
Viper
  • 405
  • 3
  • 11