Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3407804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:47:46+00:00 2026-05-18T05:47:46+00:00

I am trying to run tests on django with coverage . It works fine,

  • 0

I am trying to run tests on django with coverage. It works fine, but it doesn’t detect class definitions, because they are defined before coverage is started. I have following test runner, that I use, when I compute coverage:

import sys
import os
import logging

from django.conf import settings

MAIN_TEST_RUNNER = 'django.test.simple.run_tests'

if settings.COMPUTE_COVERAGE:
    try:
        import coverage
    except ImportError:
        print "Warning: coverage module not found: test code coverage will not be computed"
    else:
        coverage.exclude('def __unicode__')
        coverage.exclude('if DEBUG')
        coverage.exclude('if settings.DEBUG')
        coverage.exclude('raise')
        coverage.erase()
        coverage.start()
        MAIN_TEST_RUNNER = 'django-test-coverage.runner.run_tests'

def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    # start coverage - jeśli włączmy już tutaj, a wyłączymy w django-test-coverage,
    # to dostaniemy dobrze wyliczone pokrycie dla instrukcji wykonywanych przy
    # imporcie modułów
    test_path = MAIN_TEST_RUNNER.split('.')
    # Allow for Python 2.5 relative paths
    if len(test_path) > 1:
        test_module_name = '.'.join(test_path[:-1])
    else:
        test_module_name = '.'
    test_module = __import__(test_module_name, {}, {}, test_path[-1])
    test_runner = getattr(test_module, test_path[-1])
    failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
    if failures:
        sys.exit(failures)

What can I do, to have classes also included in coverage? Otherwise I have quite a low coverage and I can’t easily detect places, that really need to be covered.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:47:47+00:00Added an answer on May 18, 2026 at 5:47 am

    The simplest thing to do is to use coverage to execute the test runner. If your runner is called “runner.py”, then use:

    coverage run runner.py
    

    You can put your four exclusions into a .coveragerc file, and you’ll have all of the benefits of your coverage code, without keeping any of your coverage code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run headless tests from Jenkins. This works fine for HTML tests
I'm trying to run Selenium tests for a Django app on production server. I
Trying to run Jison unit tests, but the command fails. How do I fix
I am struggling to run unit tests using the Django Client class on the
I am trying to connect lettuce with standard django test. Lettuce works fine when
I am trying to run selenium tests I've written for a Django project on
I'm trying to run tests for my webapp. I've used Spring and Hibernate for
I'm trying to run unit tests written in QUnit using jsTestDriver. I'm getting ReferenceError:
I am trying to run automated tests on a particular product. The test consists
I'm trying to run some unit-tests for NxBRE before I start referencing it's implementation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.