I must say I am new to python mock.
I have an side_effect iterator:
myClass.do.side_effect = iter([processStatus, memoryStatus, processStatus, memoryStatus, processStatus, memoryStatus, processStatus, memoryStatus])
The above works as expected and the test cases pass
But I am looking for a better way to write this.
I tried [....]*4 which did not work.
How should I do it? Simply, making the iterator to start from the beginning once it come to the end.
I think you can use
itertools.cyclehere, if you want ‘over and over again’:Or, as @mgilson notes, if you want a finite number of 2-element terms (I’m not completely sure of what data format you need):
But as noted in the comments,
iter([1,2,3]*n)should work too.