PEP 299 and unit testing

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Oct 29 00:25:44 EDT 2007


Steven Bethard <steven.bethard at gmail.com> writes:

> Ben Finney wrote:
> > What it doesn't allow is for the testing of the 'if __name__ ==
> > "__main__":' clause itself. No matter how simple we make that,
> > it's still functional code that can contain errors, be they
> > obvious or subtle; yet it's code that *can't* be touched by the
> > unit test (by design, it doesn't execute when the module is
> > imported), leading to errors that won't be caught as early or
> > easily as they might.
> 
> You could always use runpy.run_module.

For values of "always" that include Python 2.5, of course. (I'm still
coding to Python 2.4, until 2.5 is more widespread.)

Thanks! I was unaware of that module. It does seem to nicely address
the issue I discussed.

-- 
 \         "Pinky, are you pondering what I'm pondering?" "I think so, |
  `\    Brain, but Zero Mostel times anything will still give you Zero |
_o__)                               Mostel."  -- _Pinky and The Brain_ |
Ben Finney



More information about the Python-list mailing list