[TIP] spawning a subprocess from within a pytest test

André Caron andre.l.caron at gmail.com
Tue Oct 2 09:05:07 PDT 2018


Hi Tony,

I do this regularly and it works quite well.  However, I have been caught
by environment variables not being forwarded by Tox by default.  Check
`passenv` and `setenv` environment settings.

Also, this may be unrelated to your problem, but since you mentioned
running on Windows, I'd advise paying close attention to child process
cleanup.  By default, Windows does not automatically terminte child
processes when the parent process dies.  If you start any long-running
background processes (e.g. some kind of server process managed by a session
fixture), it can end up dangling after (repeated) CTRL-C or a forceful kill
of the Python process.

Cheers,

André

On Mon, Oct 1, 2018 at 8:59 PM Bruno Oliveira <nicoddemus at gmail.com> wrote:

> Hi Tony,
>
> There's nothing in pytest that prevents you to spawn subprocesses. Posting
> your code and the error or problem you are having will probably help
> (specially if the code is small and reproduces the issue).
>
> Cheers,
> Bruno
>
> On Mon, Oct 1, 2018 at 8:51 PM Tony Cappellini <cappy2112 at gmail.com>
> wrote:
>
>>
>> I've spent a lot of time trying to figure this out, so I thought I'd ask
>> those who have more experience with Pytest.
>>
>> I'm running Python 2.7.14 on Windows 7 Pro (64-bit), pytest 3.5.0
>>
>> Is there any reason a test running under pytest shouldn't spawn a
>> subprocess, or
>> take special care when spawning it?
>>
>> I'm not able to get a subprocess to launch using subprocess.Popen()
>> inside of a pytest test, but I can run spawn the subrpocess outside of
>> pytest.
>>
>> I don't know if I can attach my code to this post.
>>
>> I'll provide more details and the code, after the reply.
>>
>> Thanks
>>
>> _______________________________________________
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
>> http://lists.idyll.org/listinfo/testing-in-python
>>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20181002/ddf1a2e6/attachment.htm>


More information about the testing-in-python mailing list