FAQ Database Discussion Community


Coverage.py suggests I need to test for an ImportError — how do I do that?

python,django,coverage.py
Just started using coverage.py and am on a testing binge! At the top of one my python files I have the following (which is used to account for differing versions of Django): try: # newer versions from django.contrib.contenttypes.fields import GenericForeignKey except ImportError: # older versions from django.contrib.contenttypes.generic import GenericForeignKey When...

How to find which branches are not covered by tests?

python,python-3.x,code-coverage,coverage.py
I am measuring code coverage of a small Python application. Although line coverage is 100%, branch coverage is not. The problem is that coverage won't give me any indication about the location of branches not being covered. coverage run --branch --omit=/usr/lib/python3/dist-packages/*,tests/* -m unittest discover returns: Ran 33 tests in 0.079s...

How to use nosetests in python while also passing/accepting arguments for argparse?

python,nose,coverage.py
I want to use nose and coverage in my project. When I run nose with --with-coverage argument, my programs argument-parsing module goes nuts because "--with-coverage" isn't a real argument according to it. How do I turn the argparse off, but during testing only? Nose says all my tests fail because...

Exclude unit tests from coverage in python

python,unit-testing,coverage.py
I am new to using coverage.py. I used coverage run unit_tests.py which ran my tests. Then I used coverage report which generated the following coverage summary: Name Stmts Miss Cover -------------------------------- cardnames 28 0 100% dominion 458 210 54% unit_tests 181 0 100% -------------------------------- TOTAL 667 210 69% Apart from...

Anyway to specify the type of report on .coveragerc?

xml,py.test,coverage.py
I'm trying to move as much as I can the configuration of pytest-cov on .coveragerc I need to replicate the --cov-report xml argument passed on the command line inside the file. I tried to use [xml] tag and output = whatever, then i found outfile and i used that one...

Code Coverage for Django Project

python,django,python-3.x,coverage.py
I installed coverage.py to measure the code coverage for my Django project. (As mentioned here: https://docs.djangoproject.com/en/1.6/topics/testing/advanced/#integration-with-coverage-py) But I currently have no test cases in my project. So, when I run coverage it says: coverage run --source='.' manage.py test myapp Creating test database for alias 'default'... ---------------------------------------------------------------------- Ran 0 tests in...

how to omit imports using .coveragerc in coverage.py?

python,unit-testing,nosetests,coverage.py
I am using nosetests --with-coverage to test and see code coverage of my unit tests. The class that I test has many external dependencies and I mock all of them in my unit test. When I run nosetests --with-coverage, it shows a really long list of all the imports (including...