A unit test that I have inherited is now failing on
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
logging.warning('Not hitting here.')
with a traceback of
Error:
File "/usr1/tsmith/miniconda3/lib/python3.7/unittest/mock.py", line 960, in __call__
return _mock_self._mock_call(*args, **kwargs)
File "/usr1/tsmith/miniconda3/lib/python3.7/unittest/mock.py", line 1022, in _mock_call
result = next(effect)
StopIteration`
Any idea how to investigate this?
StopIteration
is the normal exception sent by an iterator at the end of its iteration. For example
>>> L = [1, 2, 3]
>>> effect = iter(L)
>>> next(effect)
1
>>> next(effect)
2
>>> next(effect)
3
>>> next(effect)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
It means that the iterable 'effect' was exhausted.
(Nov-07-2019, 08:57 PM)Gribouillis Wrote: [ -> ]StopIteration
is the normal exception sent by an iterator at the end of its iteration.
It means that the iterable 'effect' was exhausted.
If it was not intentional that it be called too many times, does it imply an error?
Yes it implies an error because nobody writes applications that crash. The error comes from the code that calls the unittest.mock
module. I suppose the error traceback is longer than what you showed. Look for the last line from the application code in that traceback.
Yes, the line before it is about application code.
Error:
File "/usr1/tsmith/git/gg_database.py", line 89, in get_database_size_via_subprocess
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
And line 89 of the application code is:
side_effect = [
MockPopenResponse(stdout=stdout, status_code=self.returncode)
]
followed by
logging.warning('td90 se count = ' + str(len(side_effect)))
which returns
Output:
WARNING:root:td90 se count = 1
But I cannot seem to figure out where it is calling the mocked function when side_effect is empty.
So the title of the thread is incorrect, it should be 'mocked call to subprocess.Popen failing...'. I'm afraid this is a little too hard for me, I don't have much experience with the mock module, but perhaps someone else in the forum can answer this. It really looks like a issue with the testing rather than with the applicatino code.
(Nov-07-2019, 10:23 PM)Gribouillis Wrote: [ -> ]So the title of the thread is incorrect, it should be 'mocked call to subprocess.Popen failing...'.
It doesn't look like I'm able to change the title, but as a moderator, I would bet that you're able to. You're welcome to as far as I'm concerned.