Come the documentation stati, è possibile utilizzare trace
programmaticamente:
import sys
import trace
# create a Trace object, telling it what to ignore, and whether to
# do tracing or line-counting or both.
tracer = trace.Trace(
ignoredirs=[sys.prefix, sys.exec_prefix],
trace=0,
count=1)
# run the new command using the given tracer
tracer.run('main()')
# make a report, placing output in the current directory
r = tracer.results()
r.write_results(show_missing=True, coverdir=".")
Annotare il argomento trace.Trace
.
Sebbene non ci sia un modo per includere esplicitamente solo i file nello src
, è possibile escludere tutti i pacchetti di sistema, che, a fini pratici, dovrebbero essere gli stessi.
Ho pensato che questa soluzione inviasse i risultati a un file, ma in realtà stampasse su stdout, fantastico –