<div dir="ltr">Hello everyone,<div><br></div><div>I hope the subject is not too obscure.</div><div>The problem is this:</div><div><br></div><div>I want to write unittests for a package. The structure:</div><div><br></div><div>
I have a toplevel module, with a class, which calls a class in another module, that will then call a third class in a third module. There I&#39;ll make use of subprocess.</div><div><br></div><div>top.class.first_method() -&gt; next.class.dispatch_method() -&gt; last.class.method_using_subprocess()<br>
</div><div><br></div><div>The structure is necessary as it is. The problem here is, that the last method itself will call helper</div><div>methods within its class, which all will execute different subprocess.Popen calls, before it finally returns.</div>
<div><br></div><div>Mocking subprocess.Popen is easy with path.object etc..</div><div>But in this case, I want to unittest the first method! As long as there was only one </div><div>subproccess.Popen call to the last method, it all worked well. But now I&#39;m having trouble</div>
<div>finding a way of being able, at the toplevel, to tell a mocked subprocess down the road,</div><div>that it needs to provide different return values/stdout objects, as these depend on the</div><div>command executed. The commands are defined at the lowest level. I was thinking side_effect</div>
<div>with a custom method, but that gives me </div><div><br></div><div>side_effects_popen() takes exactly 1 argument (0 given)<br></div><div><br></div><div>And I&#39;m not sure if this is solely because of the position of the side_effect attribute to the mock</div>
<div>object or if this is the wrong approach.</div><div><br></div><div>Any help is much appreciated,</div><div>George</div></div>