[TIP] Exclufing modules from Python coverage reports

Mark lommers mlommers at hotmail.com
Thu Jan 12 10:21:21 PST 2012

We currently collect all the data coverage files and generate a combined report out of it and it is working fine
However I'm facing a problem. It is about the modules which are part of the coverage reports. I understand from the documentation that I should be able to omit certain modules and or libraries. I tried a lot the past week but am not succesful with it. Maybe you can help me with what I'm doing wrong.
when I use the following code:cov = coverage(data_file="UsefulTestResults/CoveragePython", config_file="config.coveragerc")cov.use_cache(0)cov.combine()include=get_modules_to_report_from_coveragepy_config()cov.html_report('C:\SVN\Shared\DevelopmentEhv\Products\MHServer\Trunk\Source\MHServer\core\\algorithms.pyc')
OR:cov = coverage(data_file="UsefulTestResults/CoveragePython", config_file="config.coveragerc")cov.use_cache(0)cov.combine()include=get_modules_to_report_from_coveragepy_config()cov.html_report('testproduct3\Source\MHServer\core\\algorithms.pyc')
both works, the name of the html file differs in both situation, I like the shortes one, I even prefer to get rid of testproduct3 in the last situation but it works
However when using the config file and call cov.html_report() I don't get it to work
when I add the following to my config file:
[run]source =    testproduct3\Source\MHServer\core\\algorithms.pyc
Then still everything is reported, so it looks like it doesn't use the source parameter
when I use the following in my config file
[run]include=    testproduct3\Source\MHServer\core\\algorithms.pyc
I get an exception:Traceback (most recent call last):  File "combineReport.py", line 40, in <module>    cov.html_report()  File "C:\SVN\SandBox\coveragePython\CoveragePython\coverage\control.py", line 599, in html_report    reporter.report(morfs, config=self.config)  File "C:\SVN\SandBox\coveragePython\CoveragePython\coverage\html.py", line 83, in report    self.report_files(self.html_file, morfs, config, config.html_dir)  File "C:\SVN\SandBox\coveragePython\CoveragePython\coverage\report.py", line 78, in report_files    raise CoverageException("No data to report.")coverage.misc.CoverageException: No data to report.
Furthermore in the situation where I got 1 file to work, I had to give filenames, but I like to give module names. You can imagine that giving filenames is a lot of work. From the documentation I read that it should be possible to give module names but I didn't get that to work.
In our situation we have a dir MHServer (package name??) with 4 modules (core ,fpimport, rest_ttx ,rest_generic)So i would like to configure coverage.py to report everything inside MHServer, and if that isn't possible I can also give the 4 modules  (core, fpimport, rest_ttx, rest_generic).
I also tried to ommit modules and files but I wasn't succesful either. for example we use Django which ends up in the reports.cov.html_report(omit='C:\SVN\Shared\DevelopmentEhv\Products\MHServer\Trunk\\Libs\\Django\\lib\\django\\conf\\__init__.py')cov.html_report(omit='testproduct3\\Libs\\Django\\lib\\django\\conf\\__init__.py')cov.html_report(omit='django')cov.html_report(omit='\Libs\\Django\\lib\\django\\*')
but none where excluding items from the report
Another strange thing:I tried:cov.html_report('testproduct3\\Source\\MHServer\\core\\*')that gives files directly located in that directory so that's good, But I also want reports from files located in the subdirs.
When I remove:[report]ignore_errors = true I get the followin message:coverage.misc.NoSource: No source for code: 'c:\\svn\\sandbox\\coveragepython\\testproduct3\\source\\mhserver\\core\\assetmanagement': [Errno 13] Permission denied: 'c:\\svn\\sandbox\\coveragepython\\testproduct3\\source\\mhserver\\core\\assetmanagement'I don't get why I get that message.
I hope you understand my problem/question and you can help me with it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20120112/aadb8e68/attachment.html>

More information about the testing-in-python mailing list