Coverage removes DecoratorTools's tracing function

Issue #125 resolved
Bobby Impollonia created an issue

The PEAK DecoratorTools library ( uses a tracing function to allow the use of decorators for older versions of Python.

In the past, this library conflicted with coverage because DecoratorTools would add its own tracing function and in the process remove coverage's, causing coverage to believe that no lines were executed. The current (development) version fixes this by restoring any existing tracing functions.

However, when using the current DecoratorTools library with coverage, I run into failures because coverage seems to be removing DecoratorTools's tracing function somehow: when (and only when) using coverage, functions that should be decorated by DecoratorTools act as if they do not have the decorator applied (as if DecoratorTools tracing function were removed).

I have attached a test program called With that file in the current directory, you can reproduce the problem as follows (I am using Python 2.6): {{{ virtualenv --no-site-packages myenv . myenv/bin/activate pip install ez_setup coverage distribute==0.6.14 pip install python ./ # this succeeds coverage run ./ # this throws the exception }}}

The exception is "'MyClass' object has no attribute 'name'" which indicates that our classmethod decorator has been ignored and the method is instead being treated as an instance method.

This issue causes coverage to fail when used with TurboGears applications since TG relies on PEAK Rules which relies on DecoratorTools.

Running with --timid still works, but ideally should no longer be needed now that DecoratorTools has been updated to restore coverage's tracing function.

Comments (7)

  1. Bobby Impollonia reporter

    If this turns out to be a DecoratorTools bug, PJ Eby says "If you can get the coverage developers to tell me what DecoratorTools is doing wrong, exactly, I can try to fix it.".

  2. Ned Batchelder repo owner

    Fixed in ebca9c8e46a6 . I don't know if this solves all the problems with DecoratorTools or not. I'm not a fan of it, I think it's an abuse of settrace, but I hope it works better now.

  3. Former user Account Deleted

    Thanks for looking at this.

    However, I am still seeing the issue. Using the same attached, if I change my repro steps to get coverage from hg instead of pypi:

    virtualenv --no-site-packages myenv
    . myenv/bin/activate
    pip install ez_setup hg+ distribute==0.6.14
    pip install
    python ./ # this succeeds
    coverage run ./ # this throws the exception

    , the same exception still occurs.

  4. Stefano Taschini

    I incurred in the same problem today. My solution, which seems to be working, was to patch DecoratorTools. I'm using Python 2.7.2, coverage 3.5.1, and DecoratorTools-1.8.

    Here's the patch:

    --- peak/util/	2011-10-21 10:27:15.000000000 +0200
    +++ peak/util/	2011-10-21 10:28:03.000000000 +0200
    @@ -591,7 +591,7 @@
         when multiple decorators are used).
         frame = enclosing_frame(frame, depth+1)
    -    oldtrace = [frame.f_trace]
    +    oldtrace = [sys.gettrace()]
         old_locals = frame.f_locals.copy()
         def tracer(frm,event,arg):

    I hope this helps.

  5. Log in to comment