Issue #1 open

55minutes doesn't find my app, throws weird exception

Anonymous created an issue

With the setting COVERAGE_CUSTOM_REPORTS = False in my settings.py test_coverage throws a weird Exception in utils/coverage_report/html_report.py:105

I changed it to

 try:
    overall_covered = float(total_executed)/total_stmts*100
 except ZeroDivisionError:
    overall_covered = 0

but then there are no reports in the html files, only an error message:

django_coverage.utils.module_tools.find_or_load_module had problems importing these packages and modules:

and the name of my app.

also, if i generate the a coverage.py report then i get coverage for my the entire django distribution. i have that installed in my home directory (added with PYTHONPATH), could that be the reason?

Comments (10)

  1. Mikhail Korobov repo owner
    • changed status to open

    Could you please provide the traceback?

    Also it is strange that html_report.py is executed with COVERAGE_CUSTOM_REPORTS = False because this mean that standard coverage.py reports are to be generated (and html_report.py belongs to custom 55minutes' reports).

    also, if i generate the a coverage.py report then i get coverage for my the entire django distribution. i have that installed in my home directory (added with PYTHONPATH), could that be the reason?

    Do you mean running the standard coverage.py or using django-coverage with COVERAGE_CUSTOM_REPORTS = False?

    There are special efforts to exclude django from coverage results in django-coverage. The default coverage.py behaviour is to return report for all used modules (including django).

    For the record, I personally run tests with that command:

        ./manage.py test_coverage myapp1 myapp2 --settings=test_settings
    
  2. Anonymous

    had the same problem with applications prefixed in settings.py with project name,

    INSTALLED_APPS = ( 'SOMEPROJECT.SOMEAPP', )

    Where SOMEPROJECT is a root dirictory created by manage.py startproject

  3. Anonymous

    I had the same problem - when the project name was specified in INSTALLED_APPS. When i removed the project name, the modules were found without any issue.

    Ie

    INSTALLED_APPS = ( 'SOMEPROJECT.SOMEAPP', ) [broken]

    INSTALLED_APPS = ( 'SOMEAPP', ) [works]

    Unfortunately, the second option isn't attractive to us, as it means changing some live infrastructure to fit the new path, which isn't an easy option with a high availability site.

  4. Mikhail Korobov repo owner

    Thanks for reports! I'm finally able to reproduce it.

    The things are a bit weird. There are some heavy magic inside django-coverage for loading modules and I feel scared to touch it now. I do think that this magic is unnecessary but I don't have time to rewrite these chunks of code at the moment. Patches are welcome :)

    There is a quick workaround that works for me and doesn't require live infrastructure changes:

    # test_settings.py
    from settings import *
    ...
    for index, app in enumerate(INSTALLED_APPS):
        if app.startswith('myproject.'):
            INSTALLED_APPS[index] = app.split('.',1)[1]
    

    and then:

    $ python manage.py test_coverage myapp1 myapp2 --settings=test_settings

  5. Anonymous

    django_coverage.utils.module_tools.find_or_load_module had problems importing these packages and modules:

    asteriskpeople.clustering asteriskpeople.data asteriskpeople.fixtures asteriskpeople.management.commands.recluster asteriskpeople.templates

  6. Anonymous

    But what is the fix for ZeroDivisionError (The original issue reported for this thread). I am also experiencing the same issue with newly created application/project. I have also used COVERAGE_CUSTOM_REPORTS = True explicity, but the result is the same i.e. ZeroDivisionError.

  7. Mikhail Korobov repo owner

    The workaround is to avoid complex app names (2- and more-level) in INSTALLED_APPS (e.g. by adding some folders to PYTHONPATH in test_settings.py or using some aliases during tests).

    I unfortunately don't have much time now. If somebody will provide a patch for this problem (django-coverage can't be used with complex app names) then I'll be happy to merge it.

  8. Brian Hong

    I use something like this.

    settings.py

    INSTALLED_APPS = (
        # (snip)
        'project.app1',
        'project.app2',
        'project.app3',
    )
    
    TEST_RUNNER = 'django_coverage.coverage_runner.CoverageRunner'
    COVERAGE_MODULE_EXCLUDES = [
            'tests$', 'settings$', 'urls$', 'locale$',
            'common.views.test',
            '__init__', 'django',
            'migrations',]
    

    Running

    ./manage.py test --pythonpath=..
    

    And it works fine.

  9. Log in to comment