| 235 | |
| 236 | The determining code coverage of the tests must be done during testing. Speaking about Python, some more advanced testing frameworks includes code coverage tools in them, namely [http://nedbatchelder.com/code/coverage/ coverage]. Since `unittest` does not include `coverage`, GRASS will have to incorporate `coverage` into its testing framework. The basic usage is rather simple. If we consider that all is running in one Python process, we can just put the following (rather messy) code into some module which will be loaded before the tests will start (the main invoking script would be of course the best place): |
| 237 | {{{ |
| 238 | #!python |
| 239 | import coverage |
| 240 | cov = coverage.coverage(omit="*testsuite*") |
| 241 | cov.start() |
| 242 | |
| 243 | def endcov(cov): |
| 244 | cov.stop() |
| 245 | cov.html_report(directory='testcodecoverage') |
| 246 | |
| 247 | import atexit |
| 248 | atexit.register(endcov, cov) |
| 249 | }}} |
| 250 | However, the HTML reports needs some polishing (especially the names of modules and paths) and moreover, the reports will be spitted by running different tests as separate processes. It it possible to link to these subreports and it might be even advantageous. But what is really an issue is running separate methods as separate processes, so the report is split in the way that it we have two (or more) reports, each of them reporting incomplete coverage but if merged together the coverage might be full. The merging seems like a challenge and would be probably hard on the level of HTML, so this would require using more low level API which is of course much harder. The default HTML report would be separate from the testing report, however this is not an issue and it might be even possible to add some links (with percentages) at proper places into the testing report. |