jsatt / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

side_effect Does Not Work With autospec #242

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run the attached file: python test.py

What is the expected output? What do you see instead?
Expected: Both tests pass.
Result: One test fails with this stack trace:

===================================================
ERROR: test_show_side_effect_bug (__main__.BugTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 18, in test_show_side_effect_bug
    self.assertIs(A().f1(), 1)
  File "<string>", line 3, in f1
  File "python2.7/site-packages/mock.py", line 955, in __call__
    return _mock_self._mock_call(*args, **kwargs)
  File "python2.7/site-packages/mock.py", line 1013, in _mock_call
    result = next(effect)
TypeError: list object is not an iterator

----------------------------------------------------------------------

What version of the product are you using? On what operating system?
Mock==1.0.1
OSX 10.9.5

Please provide any additional information below.
Doesn't seem to be a high priority, since the workaround is easy. I'm guessing 
fix will come either around line 1007 in mock.py, or somewhere earlier in the 
autospec-specific code.

Original issue reported on code.google.com by kenny.tr...@workiva.com on 22 Dec 2014 at 7:08

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Workaround as shown in test.py:
my_mock.side_effect = ['option1', 'option2'].__iter__()

Better:
my_mock.side_effect = iter(['option1', 'option2'])

Original comment by kenny.tr...@workiva.com on 22 Dec 2014 at 9:13

GoogleCodeExporter commented 8 years ago
 I hit this issue. today. I can see that this is fixed in Python 3 stdlib one.
Is there anyway to back port it?

Original comment by sent...@uthcode.com on 30 Jan 2015 at 4:26