PyCharm: Coverage in community edition?

时光总嘲笑我的痴心妄想 提交于 2020-07-07 23:54:30

问题


AFAIK the feature "test coverage" is only available in the professional version (code-coverage).

How to see code coverage of my tests with the PyCharm community version?


回答1:


You can use PyCrunch plugin for this.

As a bonus, tests will rerun when impacted files change.




回答2:


As you have already found, test coverage feature is available only in the professional PyCharm version.

What it's possible to do is using an external python package that perform the coverage of your test suite. This package is named coverage.
You can easily install it using the following command:

pip install coverage

Then, you can use it directly via PyCharm terminal (be sure that the interpreter is the correct one).

Here a quick example:
suppose that you have a project structure like this one

- project_name
    - src
        - some_code.py
    - unittests
        - test_1.py
        - test_2.py  

In order to run all unittests folder you have to type in PyCharm terminal the following command:

coverage run --source=./unittests -m unittest discover -s unittests/ && coverage report

Please note that in this example I'm starting the command from the project_name directory.

In this way, unittests will be ran and also a coverage will be displayed.

Another interesting option is create a HTML report. If you are interested in, please use the following command

coverage run --source=./unittests -m unittest discover -s unittests/ && coverage html

In this way a new folder will be added which contains all source for html report.

coverage package has a lot of options and it's possible customize it in different way, so please check documentation




回答3:


first you need to install coverage

pip install coverage

then run given commands(django application)

coverage run --source='.' manage.py test --keepdb
coverage report --skip-covered -m


来源:https://stackoverflow.com/questions/57767350/pycharm-coverage-in-community-edition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!