2011-01-31

PSF core grant, day 18

Spent the weekend do a little bit of writing along with a bunch of coverage debugging. A "fun" problem of working on Python is you end up in "interesting" situations that most people never have to deal with. For instance, the coverage results for some modules, (.e.g, stats) was really odd as all global statements were flagged as unexecuted.

Turns out that the stats module and others like it were simply being imported before coverage.py started running, so the normal execution side-effect of importing was not happening. But if you reload a module, that does trigger the coverage. Simple, right?

Wrong. Since reloading is not a common thing, not all modules have been tested to make sure they are robust in the face of a reload. For instance, issue 11074 has a fix for the tokenize module as it was trying to capture the built-in open() by simply assigning it to a global variable before the module defined its own open(). That fails under a reload, however, as the pre-existing module's open() gets picked up on the reload. The proper way to handle this is to use builtins.open() instead of doing the global assignment.

There are several other tests failing because of this. I'm hoping that I can narrow it down such that coverage.py, when run with its --pylib flag, can reload almost every module to get more accurate coverage information for all modules.