Using other tools with unittest?

Jp Calderone exarkun at intarweb.us
Tue Nov 18 17:50:05 EST 2003


On Tue, Nov 18, 2003 at 04:11:18PM -0600, Edward K. Ream wrote:
> Has anyone used tools like pychecker (or even Python's own debugger or
> profiler) during unit testing?  Here are some things that might be natural
> to do:
> 
> 1. pychecker can run all kinds of fancy tests on code.  I'm wondering
> whether these tests could be incorporated somehow into individual unit
> tests.  For example, one might use pychecker to assert that a subclass does,
> or does not, override a method of a base class.  Yes, one could write that
> test "by hand".  The question is: how good is pychecker for this sort of
> thing?  Anyone have any experience?

  Dunno.  The way I typically write tests, I'll just call the method.  If
it's not implemented (or implemented incorrectly), it won't behave how I
expect it to, and the test will fail.

  It might be interesting to have a "pychecker test" provided by the test
framework.  Similar to the common "at least import" tests, this could run
pychecker on all modules in a project, and fail if errors (and/or warnings)
are emitted.  I've never looked inside pychecker, I don't know how easy or
hard this would be to implement.

> 
> 2. Python's debugger is simple because Python so helpfully provides the
> sys.settrace function.  Has anyone used sys.settrace for unit testing?  For
> example, suppose you wanted to make a list of the methods that are exercised
> by a test suite.  The tracing function registered by sys.settrace could
> easily do this.  Etc.

  A few test frameworks have support for reporting code coverage.  No names
spring to mind at the moment, unfortunately.  Also, a project I work on uses
this module:

    http://www.ravenbrook.com/project/p4dti/master/test/coverage.py

  in its unit tests to generate coverage statistics (the "test" can't ever
fail; a graph is generated based on its results, though; it is run for every
checkin).

> 
> 3 In a slightly different direction, has someone used a simulation of
> aspect-oriented programming in Python to make statements about test
> coverage, or for other testing purposes?

  Not exactly sure what you're getting at here.


  Jp





More information about the Python-list mailing list