Lila25milaJan. 29, 2019, 1:53 p.m.

How to use Coverage in Django

When you are developing a large project, it is possible to accidentally forget some parts of the code that need to be tested. is a python tool to help you with this.


Use pip or easy_install as you like

pip install coverage 
Starting and uninstalling

To run in a Django project, use the command:

overage run --source='.' test the-app-you-want-to-test

This command will fill in ".coverage" which is located in COVERAGE_FILE and then you can see the results or report. If you need to delete the received data, use the command:

coverage erase
For one file

If you only want to test Python code, then you need to do:

coverage run arg1 arg2 arg3

There are several additional options that you can look at link .
You can learn about templates in the plugins section .

View result

If you want to display results on the command line:

coverage report

For clearer and more convenient reports:

coverage html

To know exactly what part of your code is covered by tests, use the following command:

coverage annotate -d directory-where-to-put-annotated-files

The program will generate the same source code file with additional syntax:

- A line with ">" means that it has been executed.

- A line starting with "!" means that it was not executed.

- A line starting with "-" means that the line has been excluded from the coverage statistics.

Good level of coverage

Good coverage is usually 90%. However, if the result is 100%, this may be a bad signal, since it may be a matter of coverage, and not the quality of the tests.

A few tips:

- Be careful with the quality of your tests.

- Don't slow down your developer speeds for the sake of coverage.

- Use coverage to find unverified code and decide if it deserves coverage.

Exclude code

Sometimes we need to exclude some code that doesn't need coverage. There are several options:

- Specifying files to exclude and skip in .coveragerc.

- Writing in one line of the comment block.

 # pragma: no cover

For example, if you want to exclude generated code from coverage because it must be supported by the generation tool:

def generated_code():   # pragma: no cover

More info at documentation.

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.


Only authorized users can post comments.
Please, Log in or Sign up
Card image cap
Pulsum Via

Project for travelers from EVILEG.


Let me recommend you a great European Fornex hosting.

Fornex has proven itself to be a stable host over the years.

For Django projects I recommend VPS hosting

Following the link you will receive a 5% discount on shared hosting services, dedicated servers, VPS and VPN

View Hosting
Share on social networks

The EVILEG project has switched to a non-commercial basis and will develop solely on the enthusiasm of the site creator, the enthusiasm of users, donations and the hosting referral system

Thank you for your support

Available ways to support the project



C ++ - Test 004. Pointers, Arrays and Loops

  • Result:20points,
  • Rating points-10

C++ - Test 005. Structures and Classes

  • Result:83points,
  • Rating points4

C++ - Test 002. Constants

  • Result:58points,
  • Rating points-2
Last comments

Android and QML - Adding Splash Screen

Интересен формат иконки, если это png, то как решается проблема scalability? не растягивается ли лого на китайфонах с 1280х2500? У меня просто сплеш скрин с градиентом и логотипом, и вот несколь…

Qt/C++ - Lesson 023. Moving QGraphicsItem on QGraphicsScene with mouse help

FIGURE Abdominopelvic regions. Zjuaqd - Cialis Cialis Recommendations for preparing children and adolescents for invasive cardiac procedures a statement…

How to use nested forms in Django

Спасибо за полезную статью. Подскажите пожалуйста, что делать если нужно реализовать большее количество вложенных форм? Например если на модель Address ссылается fk другой модели, на котору…

Qt/C++ - Lesson 051. QMediaPlayer – simple audio player

Не думаю, QMediaPlayer в один поток проигрывает. Если вам нужно одновременное воспроизведение нескольких аудиоисточников, то вам нужна Bass audio library , насколько знаю, её обычно и…

Qt/C++ - Lesson 051. QMediaPlayer – simple audio player

есть такая вообще возможность ?
Now discuss on the forum

Sorting the added QML elements in the ListModel

I am writing an alarm clock in QML, I am required to sort the alarms in ascending order (depending on the date or time (if there are several alarms on the same day). I've done the sorting …

Изменение поведения QGroupBox при клике на его чекбокс

Я вынес виджеты вынес за пределы QGroupBox в итоге.

QSqlRelatipnalTabelModel Qt 4.8.1 как получить id внешней связи?

Есть еще принципиально другой вариант решить раз и навсегда вопрос с полей id внешней связи. Это форкнуть Qt 4.8.1 QSqlTableModel, то есть создать свою ветку развития. Например создадим кл…

Добавление AndroidManifest.xml в cmake

Добрый день. Как добавить AndroidManifest.xml в cmake? Это не работвет set(ANDROID_PACKAGE_SOURCE_DIR ${PROJECT_SOURCE_DIR}/android CACHE INTERNAL "")set(ANDROID_BUID_DIR ${CMAKE_C…

Событие wheelEvent для виджета QLineEdit

вот что получилось: from PyQt5 import QtCore, QtGui, QtWidgets class LineEdit(QtWidgets.QLineEdit): def wheelEvent(self, event): #print("_") delta = 1 if e…
© EVILEG 2015-2022
Recommend hosting TIMEWEB