简体   繁体   English

从 PyCharm 内部使用 pytest-cov 插件

[英]Using pytest-cov plugin from inside PyCharm

I want to use pytest and pytest-cov plugin from inside PyCharm, so I added --cov=package to "Additional arguments" entry field when I edited my configuration.我想从 PyCharm 内部使用 pytest 和 pytest-cov 插件,因此我在编辑配置时将--cov=package添加到“附加参数”输入字段。 However, I get both the output and the error, not sure why:但是,我得到了输出和错误,不知道为什么:

Testing started at 4:50 PM ...
/home/alex/.repos/codelib/github/dsa/env/bin/python /home/alex/Downloads/pycharm-2019.3.4/plugins/python/helpers/pycharm/_jb_pytest_runner.py --path /home/alex/.repos/codelib/github/dsa/ -- --cov=bag
Launching pytest with arguments --cov=bag /home/alex/.repos/codelib/github/dsa/ in /home/alex/.repos/codelib/github/dsa/bag/tests

============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- /home/alex/.repos/codelib/github/dsa/env/bin/python
cachedir: .pytest_cache
rootdir: /home/alex/.repos/codelib/github/dsa
plugins: cov-2.8.1
collecting ... collected 1 item

test_simple_bag.py::test_len PASSED                                      [100%]

Coverage statistics reporting failed
Traceback (most recent call last):
  File "/home/alex/Downloads/pycharm-2019.3.4/plugins/python/helpers/pycharm/teamcity/pytest_plugin.py", line 371, in pytest_terminal_summary
    self._report_coverage()
  File "/home/alex/Downloads/pycharm-2019.3.4/plugins/python/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
----------------------------------------------------------------------------
/home/alex/.repos/codelib/github/dsa/bag/__init__.py         0      0   100%
/home/alex/.repos/codelib/github/dsa/bag/simple_bag.py      17      5    71%
__init__.py                                                  0      0   100%
test_simple_bag.py                                           6      0   100%
----------------------------------------------------------------------------
TOTAL                                                       23      5    78%


============================== 1 passed in 0.03s ===============================

Process finished with exit code 0

When I run tests from the terminal, everything goes fine:当我从终端运行测试时,一切正常:

(env) alex@smartalex-pc:~/.repos/codelib/github/dsa$ pytest --cov=bag
============================================== test session starts ===============================================
platform linux -- Python 3.6.9, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/alex/.repos/codelib/github/dsa
plugins: cov-2.8.1
collected 1 item                                                                                                 
​
bag/tests/test_simple_bag.py .                                                                             [100%]
​
----------- coverage: platform linux, python 3.6.9-final-0 -----------
Name                           Stmts   Miss  Cover
--------------------------------------------------
bag/__init__.py                    0      0   100%
bag/simple_bag.py                 17      5    71%
bag/tests/__init__.py              0      0   100%
bag/tests/test_simple_bag.py       6      0   100%
--------------------------------------------------
TOTAL                             23      5    78%
​
​
=============================================== 1 passed in 0.03s ================================================
(env) alex@smartalex-pc:~/.repos/codelib/github/dsa$ 

That's because PyCharm's test plugin didn't adapt to breaking changes in coverage>=5.0 yet.这是因为 PyCharm 的测试插件还没有适应coverage>=5.0重大变化。 Here's a related issue in JetBrain's tracker: PY-40980 .这是 JetBrain 跟踪器中的一个相关问题: PY-40980 Until the issue is fixed, pin coverage to previous major:在问题解决之前,将coverage固定到以前的专业:

$ pip install 'coverage<5'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM