Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage removes DecoratorTools's tracing function #125

Closed
nedbat opened this issue Mar 22, 2011 · 4 comments
Closed

Coverage removes DecoratorTools's tracing function #125

nedbat opened this issue Mar 22, 2011 · 4 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Mar 22, 2011

Originally reported by Bobby Impollonia (Bitbucket: bobbyi, GitHub: bobbyi)


The PEAK DecoratorTools library (http://pypi.python.org/pypi/DecoratorTools) 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 dec.py. 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 http://svn.eby-sarna.com/DecoratorTools.tar.gz?view=tar
python ./dec.py # this succeeds
coverage run ./dec.py # 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.


@nedbat
Copy link
Owner Author

nedbat commented Mar 22, 2011

Original comment by Bobby Impollonia (Bitbucket: bobbyi, GitHub: bobbyi)


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.".

@nedbat
Copy link
Owner Author

nedbat commented Apr 27, 2011

Fixed in <<changeset ebca9c8e46a6 (bb)>>. 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.

@nedbat
Copy link
Owner Author

nedbat commented May 2, 2011

Original comment by Anonymous


Thanks for looking at this.

However, I am still seeing the issue. Using the same attached dec.py, 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+https://bitbucket.org/ned/coveragepy distribute==0.6.14
pip install http://svn.eby-sarna.com/DecoratorTools.tar.gz?view=tar
python ./dec.py # this succeeds
coverage run ./dec.py # this throws the exception

, the same exception still occurs.

@nedbat
Copy link
Owner Author

nedbat commented Oct 21, 2011

Original comment by Stefano Taschini (Bitbucket: taschini, GitHub: 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/decorators.py.orig	2011-10-21 10:27:15.000000000 +0200
+++ peak/util/decorators.py	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.

@nedbat nedbat closed this as completed Oct 21, 2011
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
agronholm added a commit to agronholm/coveragepy that referenced this issue Aug 16, 2020
This replaces accept() with serve() which in turn obsoletes anyio.serve_listeners() which did not make it into any release.
Among other things, this lets us do the TLS handshake in the newly spawned handler task.

Fixes nedbat#125.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant