During my Udacity Class CS258 I was introduced to Coverage.py. You can read up on Code Coverage on Wikipedia but I would also recommend the free course on the subject via Udacity.
To get Coverage.py running on your installation, the easiest way is using the console command easy_install. If you are using PythonPortable, you need to navigate to AppScripts before executing the following command:
Easy, wasn’t it?
PyScripter is a neat IDE packaged with PythonPortable. It has a feature called External Tools (found under the menu Tools->Tools). To make a neat shortcut you can “Configure Tools..” under the same menu.
Here are two shortcuts, one for running coverage on one file, the other for constructing the HTML:
[ToolsTool11ExternalTool] Caption=Coverage Description=http://nedbatchelder.com/code/coverage/ ApplicationName=$[PythonDir-Short]Scriptscoverage.exe Parameters=run $[ActiveDoc-Short] $[CmdLineArgs] WorkingDirectory=$[ActiveDoc-Dir] ShortCut=0 Context=tcActivePythonFile SaveFiles=sfActive ParseTraceback=TRUE MessagesFormat=$[FileName] $[LineNumber] ConsoleHidden=FALSE [ToolsTool12ExternalTool] Caption=Coverage HTML Description=http://nedbatchelder.com/code/coverage/ ApplicationName=$[PythonDir-Short]Scriptscoverage.exe Parameters=html WorkingDirectory=$[ActiveDoc-Dir] ShortCut=0 Context=tcActiveFile ParseTraceback=TRUE MessagesFormat=$[FileName] $[LineNumber] ConsoleHidden=FALSE
Just pasting this inside PyScripter.ini does require some additional fiddling, so I recommend just using the gui. The new commands will appear inside Tools->Tools. The generated HTML will be inside the scripts working directory.
Now go do some coverage testing!