Testing automatically on import (was: Re: allowing braces around suites)

Jeremy Bowers jerf at jerf.org
Sat Aug 28 16:30:10 EDT 2004


On Sat, 28 Aug 2004 12:15:24 +0200, Alex Martelli wrote:

> Hmmm -- I'm thinking that the existing import hooks might be enough to
> let one prototype this "automatic checking" functionality, not quite as
> smoothly as a fully architected system maybe, but enough to get some
> early adopters, shake out teething problems, build a constituency to
> lobby for smoother integration in a future Python version...

You know, I'm totally unexcited about the syntax stuff this thread is
putatively about, but running automated testing over newly imported stuff
sounds kind of useful, not just for development but deployment as well;
"forcing" the users to run the tests once and report problems could be
very useful in some contexts. 

I already tend to name my unit tests for file "x.py" as "tests/xTest.py"...

Maybe something that looks for a __validate__ function taking no args in a
module and runs it if the code was imported and newly compiled, combined
with a few convenience functions for the common cases?

I'm not *quite* familiar with the import hook stuff to knock this off
right away. I tried prototyping it but got stuck on how to determine if a
Python file already has an up-to-date .pyc file. (Although I guess there
may be external dependencies... well in the interest of keeping it simple,
deal with that later.)



More information about the Python-list mailing list