[TIP] Using coverage.py with code that uses sys.settrace()

Leahy, Oliver oliver.leahy at hp.com
Wed Dec 28 07:58:07 PST 2011

What's the recommended way to use coverage.py with code that uses sys.settrace()

I'm using settrace() to simulate error conditions at certain lines during testing, but
this interferes with the use coverage.py makes of settrace() and I'm getting incorrect
coverage metrics.

I'm hacking at my code to try to store an existing value for sys.gettrace() whenever
I call settrace(),  and then restoring the pre-existing trace function whenever I stop
tracing using my function, but it's not working for me at the moment.

Is this a sensible approach to this problem?  Would anyone have any other suggestions?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20111228/bf44b883/attachment.html>

More information about the testing-in-python mailing list