Skip to content

subprocess_exec causing setup and teardown errors #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RouquinBlanc opened this issue Sep 27, 2018 · 2 comments
Closed

subprocess_exec causing setup and teardown errors #98

RouquinBlanc opened this issue Sep 27, 2018 · 2 comments

Comments

@RouquinBlanc
Copy link

Hi,

I've been troubleshooting for the past days an issue which puzzles me...
Our app spawns some suprocesses, and I was having some random failures either in setup of teardown of my pytest-asyncio test cases.

This is the very minimal code to reproduce, after removing everything else:

import asyncio
import pytest
import sys

@pytest.mark.parametrize('attempt', range(100))
@pytest.mark.asyncio
async def test_subprocess(attempt):
    # Initialise a lot of stuff, including a subprocess
    transport, _ = await asyncio.get_event_loop().subprocess_exec(
        asyncio.SubprocessProtocol, sys.executable
    )

    # Close everything, including our previous transport
    transport.close()

My first random guess would be some late cleanup code which would corrupt the next event loop associated with next test... especially because if I wait a bit after closing, or await transport._wait(), the problem disappears.

The problem appears when running multiple pytest-asyncio testcase in a row, but does not appear at all if the loop remains untouched, which is the case in our app. I can work around this situation in various ways, but I'm wondering if the test fixture could not protect from this kind of errors instead???

Note that the issue appears mainly on Ubuntu in my case, which I can hardly reproduce it on mac os.

Test output here

@Tinche
Copy link
Member

Tinche commented Sep 30, 2018

Hi,

it'd be great if you could dig into this a little more and maybe submit a PR to fix it?

@seifertm seifertm changed the title Issue with asyncio subprocess subprocess_exec causing setup and teardown errors Jan 16, 2022
@seifertm
Copy link
Contributor

@RouquinBlanc Thanks for the report and the minimal example!

I cannot reproduce the issue using pytest-asyncio 0.17.0. I consistently get 100 successful tests on my Linux machine. Possibly the issue has been resolved.

If you continue to experience problems with a more recent version of pytest-asyncio feel free to reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants