-1

I am trying to perform something similar to this:

mymock = Mock()
mymock.variable.side_effect = [1,2,3]
print mymock.variable # Should print 1
print mymock.variable # Should print 2
print mymock.variable # Should print 3

However, I am not getting the desired outcome. What am I missing?

Voldemort
  • 181
  • 1
  • 9

1 Answers1

1

Using side_effect only applies when the attribute is called as a method:

In [3]: mymock = Mock()

In [4]: mymock.variable.side_effect = [1,2,3]

In [5]: mymock.variable()
Out[5]: 1

In [6]: mymock.variable()
Out[6]: 2

In [7]: mymock.variable()
Out[7]: 3

There is no similar functionality for assigning a value to the an attribute.

jordanm
  • 33,009
  • 7
  • 61
  • 76