Skip to content
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

Cannot run pytest-cov with ddtrace installed in the same project #11256

Open
ddarricau opened this issue Oct 31, 2024 · 2 comments
Open

Cannot run pytest-cov with ddtrace installed in the same project #11256

ddarricau opened this issue Oct 31, 2024 · 2 comments
Assignees
Labels

Comments

@ddarricau
Copy link

ddarricau commented Oct 31, 2024

Summary
Basically I am unable to run test coverage on a project that includes both ddtrace and pytest-cov

Expected vs actual result
I should be able to do so

Reproducer
In order to reproduce I have a very simple project with

[tool.poetry.dependencies]
python = "^3.12"
pytest = "^8.3.3"
pytest-cov = "^6.0.0"
ddtrace = "2.12.0"

And a test file

def test_ddtrace_coverage():
    assert 1 == 1

Whenever I run the command COVERAGE_FILE=foo COVERAGE_CORE=sysmon pytest --cov=. tests/test_ddtrace_coverage.py I get the following error

  File "/Users/didierdarricau/Library/Caches/pypoetry/virtualenvs/ddtrace-coverage-test-5TsU0QvL-py3.12/lib/python3.12/site-packages/coverage/sysmon.py", line 226, in start
    sys_monitoring.use_tool_id(self.myid, "coverage.py")
ValueError: tool 1 is already in use

Note that this only happens when using the COVERAGE_CORE=sysmon flag, it seems that both ddtrace and pytest-cov request the same tool_id in that module. Note that using this flag is important to me as it significantly shortens the CI run time at my job.

I am not sure who should resolve the issue so I am also posting an issue on the pytest-cov repo.

Also not that if I use a ddtrace version < 2.12.0 it works fine.

@romainkomorndatadog
Copy link
Contributor

Thanks for the report, @ddarricau .

We're winning the race to sys_monitoring.use_tool_id() with our own call as a result of imports, but the main issue is that we shouldn't be calling use_tool_id() unless we're actually collecting coverage.

@vitor-de-araujo or I should refactor the code so that we only call use_tool_id() if instrument_all_lines() is actually called.

@ddarricau
Copy link
Author

Great thank you !

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

No branches or pull requests

3 participants