首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PyCharm内部使用pytest-cov插件

在PyCharm内部使用pytest-cov插件
EN

Stack Overflow用户
提问于 2020-04-01 23:05:36
回答 1查看 1.3K关注 0票数 2

我想从PyCharm内部使用pytest和pytest-cov插件,所以我在编辑配置时将--cov=package添加到了“附加参数”输入字段中。但是,我同时得到了输出和错误,不确定原因:

代码语言:javascript
复制
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

当我从终端运行测试时,一切都很正常:

代码语言:javascript
复制
(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$ 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-02 01:26:34

这是因为PyCharm的测试插件还不能适应coverage>=5.0的突破性变化。在JetBrain的追踪器中有一个相关的问题:PY-40980。在问题解决之前,将coverage固定到以前的主要版本:

代码语言:javascript
复制
$ pip install 'coverage<5'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60974076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档