[Twisted-Python] Coverage summary with trial

Øystein S. Haaland oystein.s.haaland at gmail.com
Fri Apr 13 17:03:28 EDT 2012

Hi all,

I would like to collect coverage statistic for my twisted code with trial and 
was wondering how to achieve this.

I run something like:
	$ trial --coverage testdir/*_test.py

all tests are green and i can see coverage files in _trial_temp/coverage/.

After looking around a bit i learn that the python trace module is used under 
the hood and my assumption then is that i must use similar commands as those 
that are shown here:


I had to look at the source code to find this out. It would be nice if it was 
mentioned in the documentation somewhere.

So i try to construct a command like this:

python -m trace --summary --report --coverdir _trial_temp/coverage/

But it needs --file which seems not to be enabled by trial. I then make some 
changes in the trial script:

--- trial.py.orig       2012-03-30 06:32:08.627758872 +0200
+++ trial.py    2012-04-14 04:50:05.416382063 +0200
@@ -162,7 +162,8 @@
         directory specified by the I{trial-temp} option.
         import trace
-        self.tracer = trace.Trace(count=1, trace=0)
+       countfile="countfile.txt"
+        self.tracer = trace.Trace(count=1, trace=0, infile=countfile, 

and i can finally see a summary if i remember to add the --missing option:

python -m trace --report --summary --missing --file countfile.txt --

I assume i am missing something obvious, because it seems strange that one 
would have to change the trial script to achieve this. How do other people 
create such summaries?



More information about the Twisted-Python mailing list