PyCharm + Pytest + pytest-cov = Viewer always shows 0%

I'm contributing to an open source project that relies on pytest + pytest-cov. My interpreter is configured as a Docker (not compose) based Python interpreter from an existing image (built manually).

I'm able to run tests OK, both on a standalone shell, as well as with the run configuration below:

And I get this output:

/usr/local/bin/python3 -m pytest --cov=homeassistant.components.digital_ocean --cov-report=xml --cov-report=term-missing --cov-branch ./tests/components/digital_ocean/ 
============================= test session starts ==============================
platform linux -- Python 3.11.4, pytest-7.4.3, pluggy-1.3.0
rootdir: /workspace/homeassistant
configfile: pyproject.toml
plugins: socket-0.6.0, aiohttp-1.0.5, unordered-0.5.2, test-groups-1.0.3, requests-mock-1.11.0, picked-0.5.0, asyncio-0.21.0, pytest_freezer-0.4.8, respx-0.20.2, xdist-3.3.1, sugar-0.9.7, timeout-2.1.0, rerunfailures-13.0, anyio-4.0.0, cov-4.1.0, syrupy-4.6.0, mock-3.12.0
asyncio: mode=Mode.AUTO
collected 1 item

tests/components/digital_ocean/test_init.py .                            [100%]

---------- coverage: platform linux, python 3.11.4-final-0 -----------
Name                                                      Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------------------------------
homeassistant/components/digital_ocean/__init__.py           75     25     16      1    60%   58-62, 86-93, 100-118, 126
homeassistant/components/digital_ocean/binary_sensor.py      47     47     18      0     0%   2-111
homeassistant/components/digital_ocean/constants.py           7      0      0      0   100%
homeassistant/components/digital_ocean/exceptions.py          4      0      0      0   100%
homeassistant/components/digital_ocean/schemas.py             4      0      0      0   100%
homeassistant/components/digital_ocean/services.py           19     13      2      0    29%   22-55
homeassistant/components/digital_ocean/switch.py             51     51     20      0     0%   2-114
-----------------------------------------------------------------------------------------------------
TOTAL                                                       207    136     56      1    29%
Coverage XML written to file coverage.xml


============================== 1 passed in 0.26s ===============================

Process finished with exit code 0

As you can see, Coverage is being captured and assessed, but then I load this file into PyCharm, I only see 0%:

What I am doing wrong?

EDIT:

I've also tried using the bundled coverage.py and using PyCharm's “Run with Coverage” feature, but it achieves the same results. For this I've added the `--no-cov` modifier to pytest:

/usr/local/bin/python3 /opt/.pycharm_helpers/coverage_runner/run_coverage.py run --branch --omit="/Users/peixoto/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/232.10227.11/PyCharm.app/Contents/plugins/python/helpers*" -m pytest --no-cov --cov=homeassistant.components.digital_ocean --cov-report=xml --cov-report=term-missing --cov-branch ./tests/components/digital_ocean/ 
Loading rcfile: /workspace/homeassistant/.coveragerc

============================= test session starts ==============================
platform linux -- Python 3.11.4, pytest-7.4.3, pluggy-1.3.0
rootdir: /workspace/homeassistant
configfile: pyproject.toml
plugins: socket-0.6.0, aiohttp-1.0.5, unordered-0.5.2, test-groups-1.0.3, requests-mock-1.11.0, picked-0.5.0, asyncio-0.21.0, pytest_freezer-0.4.8, respx-0.20.2, xdist-3.3.1, sugar-0.9.7, timeout-2.1.0, rerunfailures-13.0, anyio-4.0.0, cov-4.1.0, syrupy-4.6.0, mock-3.12.0
asyncio: mode=Mode.AUTO
collected 1 item

tests/components/digital_ocean/test_init.py .INFO:homeassistant.loader:Loaded digital_ocean from homeassistant.components.digital_ocean
INFO:homeassistant.setup:Setting up digital_ocean
INFO:homeassistant.setup:Setup of domain digital_ocean took 0.0 seconds

WARNING: Coverage disabled via --no-cov switch!

=============================== warnings summary ===============================
../../usr/local/lib/python3.11/site-packages/pytest_cov/plugin.py:324
  /usr/local/lib/python3.11/site-packages/pytest_cov/plugin.py:324: CovDisabledWarning: Coverage disabled via --no-cov switch!
    warnings.warn(CovDisabledWarning(message))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================= 1 passed, 1 warning in 0.30s =========================
Wrote XML report to /tmp/527940ac-15c9-41e8-ad3e-639cb33ddb43/home_assistant_core$pytest.xml

Process finished with exit code 0

 

1
1 comment
Hi, could you please provide the full command you use to run the coverage suite from the terminal? I will try to reproduce the issue.
0

Please sign in to leave a comment.