-
Notifications
You must be signed in to change notification settings - Fork 211
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
pytest-cov fails with pytest-xdist and dynamic_context = "test_function" #604
Comments
I have managed to reproduce the problem but I don't understand what's the point of using dynamic_context=test_function when pytest-cov's The problem is caused by should_start_context_test_function triggering a switch in the middle of some xdist internals (xdist.scheduler.load.tests_finished). Please justify your usecase. I think the only reasonable thing to do here is make pytest-cov raise an error when it detects that you are using dynamic_context=test_function and xdist, and a warning when you are using just dynamic_context=test_function. |
To give some context, this is the implementation of def should_start_context_test_function(frame: FrameType) -> str | None:
"""Is this frame calling a test_* function?"""
co_name = frame.f_code.co_name
if co_name.startswith("test") or co_name == "runTest":
return qualname_from_frame(frame)
return None You will notice that
|
Summary
I am trying to use pytest-cov fails with pytest-xdist and want to get coverage for each trace function to ultimately see which lines and arcs are covered by which test function (which I'll then use to create a minimal set of tests that generate n% coverage eliminating redundant tests).
I can use a static context with
--cov-context=test
together with pytest-xdist but when I trydynamic_context = "test_function"
I get an internal error.Reproducer
This works:
The relevant sections of my
pyproject.toml
are:Edit
pyproject.toml
to remove the comment fordynamic_context
. I also removed--cov-context=test
but that doesn't make any difference in that the internal error still happens.Then re-run
poetry run pytest -n logical tests/test_version.py
and I observe an internal error:My config includes some
adopts
for pytest but commenting those out and usingpoetry run pytest -n logical --cov=src/numbers_parser tests/test_version.py
alone is sufficient to crash. Playing around with arguments I can see ordering doesn't help but the number of threads does. At least on my test machine:poetry run pytest --cov=src/numbers_parser -n 1 tests/test_version.py
succeedspoetry run pytest --cov=src/numbers_parser -n 2 tests/test_version.py
succeedspoetry run pytest --cov=src/numbers_parser -n 3 tests/test_version.py
failsVersions
The text was updated successfully, but these errors were encountered: