Testing automatically on import
aleaxit at yahoo.com
Mon Aug 30 09:05:12 CEST 2004
Jeremy Bowers <jerf at jerf.org> wrote:
> 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,
Hmmm, yeah, it DID start out about braces, didn't it?-)
> 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 agree with you entirely.
> I already tend to name my unit tests for file "x.py" as "tests/xTest.py"...
I tend to use tests/test_x.py, myself, but here we're back to discussing
syntax sugar again;-).
> 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.)
Hmmm, I could be wrong, but I think you have to check timestamps and
'magic' signatures yourself. Pity, because imp.load_module must also do
that, but I don't think it makes this logic available separately.
Still, I believe Demo/imputil/importers.py has all the code you need.
More information about the Python-list