pytest-dev / pytest-cov

Coverage plugin for pytest.
MIT License
1.72k stars 211 forks source link

Coverage with subproprocess Popen and async code #608

Closed gilcu2 closed 11 months ago

gilcu2 commented 11 months ago

Summary

TCP server on trio running from a fixture:

@pytest.fixture(scope="session")
def server() -> Generator:
    server_proc = subprocess.Popen(
        [
            sys.executable,
            "src/server.py",
        ],
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
    )
    time.sleep(0.1)
    assert not server_proc.poll()
    assert "TCP listening on 1234" in server_proc.stdout.read().decode("utf-8")  # type: ignore
    yield server_proc
    server_proc.terminate()

The sync lines of server.py get coverage but the async no. I have tried several combination like:

but don't get the coverage

Expected vs actual result

Async lines covered. I know they run because I have log feedback

Reproducer

Versions

python = "^3.11" anyio = { extras = ["trio"], version = "^4.0.0" } pytest = "^7.4.0" pytest-cov = "^4.1.0"

Config

[tool.coverage.run]

concurrency = ["greenlet"]

concurrency = ["thread","gevent"]

concurrency = ["greenlet", "thread"]

sigterm = "true"

ionelmc commented 11 months ago

I think a more complete reproducer is required here.

gilcu2 commented 11 months ago

Hi sorry. Was my fault. The server under pytest was not running because the same server was running alone in the same port.