Running pytest with --cov produces results but fails to import coverage report module

Answered

PyCharm 2019.3.3 CE

Running pytest configuration with --cov option fails with an ImportError in the Run window. The test results display as well as the coverage results after the failure lines. I've tried reinstalling pycharm, tried the latest snap, and tried on windows as well with the same results. 

Coverage statistics reporting failed
Traceback (most recent call last):
File "/opt/pycharm-community-2019.3.3/plugins/python-ce/helpers/pycharm/teamcity/pytest_plugin.py", line 371, in pytest_terminal_summary
self._report_coverage()
File "/opt/pycharm-community-2019.3.3/plugins/python-ce/helpers/pycharm/teamcity/pytest_plugin.py", line 378, in _report_coverage
from coverage.report import Reporter
ImportError: cannot import name 'Reporter'

 

Full output

Testing started at 9:45 AM ...
/home/jason/Development/calculator/venv/bin/python /opt/pycharm-community-2019.3.3/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py --path /home/jason/Development/calculator -- --cov=calculator tests/
Launching pytest with arguments --cov=calculator tests/ /home/jason/Development/calculator in /home/jason/Development/calculator

============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-5.3.5, py-1.8.1, pluggy-0.13.1 -- /home/jason/Development/calculator/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/jason/Development/calculator
plugins: cov-2.8.1
collecting ... collected 20 items

tests/test_calculator.py::TestAdd::test_add PASSED [ 5%]
tests/test_calculator.py::TestAdd::test_add_parametrize[1-1-2] PASSED [ 10%]
tests/test_calculator.py::TestAdd::test_add_parametrize[2-1-3] PASSED [ 15%]
tests/test_calculator.py::TestAdd::test_add_parametrize[3-1-4] PASSED [ 20%]
tests/test_calculator.py::TestAdd::test_add_parametrize[4-1-5] PASSED [ 25%]
tests/test_calculator.py::TestAdd::test_add_parametrize[5-1-6] PASSED [ 30%]
tests/test_calculator.py::TestAdd::test_add_parametrize[6-1-7] PASSED [ 35%]
tests/test_calculator.py::TestAdd::test_add_parametrize[7-1-8] PASSED [ 40%]
tests/test_calculator.py::TestAdd::test_add_parametrize[8-1-9] PASSED [ 45%]
tests/test_calculator.py::TestAdd::test_add_parametrize[9-1-10] PASSED [ 50%]
tests/test_calculator.py::TestAdd::test_add_weird_stuff PASSED [ 55%]
tests/test_calculator.py::TestAdd::test_add_weirder_stuff PASSED [ 60%]
tests/test_calculator.py::TestSubtract::test_subtract PASSED [ 65%]
tests/test_calculator.py::TestMultiply::test_multiply PASSED [ 70%]
tests/test_calculator.py::test_divide PASSED [ 75%]
tests/test_calculator.py::test_divide_by_zero PASSED [ 80%]
tests/test_calculator.py::test_fixture PASSED [ 85%]
tests/test_calculator.py::test_capsys PASSED [ 90%]
tests/test_calculator.py::test_monkeypatch PASSED [ 95%]
tests/test_calculator.py::test_fixture_with_fixtures hello
PASSED [100%]

Coverage statistics reporting failed
Traceback (most recent call last):
File "/opt/pycharm-community-2019.3.3/plugins/python-ce/helpers/pycharm/teamcity/pytest_plugin.py", line 371, in pytest_terminal_summary
self._report_coverage()
File "/opt/pycharm-community-2019.3.3/plugins/python-ce/helpers/pycharm/teamcity/pytest_plugin.py", line 378, in _report_coverage
from coverage.report import Reporter
ImportError: cannot import name 'Reporter'


----------- coverage: platform linux, python 3.6.9-final-0 -----------
Name Stmts Miss Cover
----------------------------------------------
calculator/calculator.py 19 0 100%


============================== 20 passed in 0.09s ==============================

Process finished with exit code 0

1
2 comments
Avatar
Permanently deleted user

This same error also occurs in PyCharm Pro 2019.3.3, I initially thought it was a Community Edition issue but it is occurring in both editions.

0

Please sign in to leave a comment.