Issue #192 invalid

Coverage report broken by lambda function

Julian Simioni
created an issue

Hi, I'm using coverage 3.5.2 in combination with nose to display coverage reports for my Django app. Recently I started using the code found at http://djangosnippets.org/snippets/873/ to easily make settings variables available in templates. Unfortunately, this appears to break the coverage reports with the error shown in coverageError.txt

I was able to fix the error with the attached patch. The first change fixes the actual error, and the change farther down the file removes a duplicate entry in the list of coverage units (there would be one for a function, and then an identical one for the function returning the lambda expression)

Let me know if you need any more details, and thanks for making coverage so awesome!

Comments (6)

  1. Ned Batchelder repo owner

    ugh, Julian, this is horrible! That Django snippet is broken, and is giving a function for .name of its "module". I don't know that I want to add this weirdness to coverage.py. Can't we fix the Django snippet instead?

  2. Ned Batchelder repo owner

    BTW, this snippet also seems way more convoluted than it needs to be? Why not just write a context processor that adds the settings you want to the context? Here's one that still allows you to configure the settings to use in settings.py:

    # utils/context_processor.py
    
    from django.conf import settings
    
    def some_settings(request):
        return dict( # wrapped oddly to stay narrow
            (k, getattr(settings, k)) 
            for k in settings.SETTINGS_IN_CONTEXT
        )
    
    # settings.py
    TEMPLATE_CONTEXT_PROCESSORS = (
        # ....
        'utils.context_processors.some_settings',
    }
    
    SETTINGS_IN_CONTEXT = ['GOOGLEMAPS_KEY', 'TEMPLATE_DEBUG', 'MAXMIND_URL']
    

    This will work properly, with less overhead (one context processor instead of N), be understandable, and won't break other parts of your system.

  3. Julian Simioni reporter

    Okay, that's actually much better. I realized the original snippet was a bit janky but didn't fully appreciate how truly disasterous it is. You're right that the intended functionality can be had much more easily. Carry on with the coverage code as is!

  4. Log in to comment