excluding unit test code
Steven Haryanto
steven at haryan.to
Tue Apr 3 09:56:51 EDT 2001
At 4/3/2001 06:54 AM, you wrote:
> What do you mean by "exclude"?
The same way -OO excludes doc-string from the source
code, i.e.: it is optimized away by the compiler,
and never gets into the object code/loaded into
memory/executed.
> If this were C,
> I'd say that you could just use "#if 0" around the
> test blocks for when you ship production code.
> The quick way is to convert:
>
> some_test_code()
>
> into
>
> if None:
> some_test_code()
>
> if that's OK with you. That way it will never be
> executed. How else you would do it depends on your
> definition of "excluded". You could hide it in
> another module, or just cut it out altogether.
After being advised by Steve Purcell, I think I will go
with something like 'if __DEBUG__' instead of 'if 0' or
'#if DEBUG' (running the Python source through cpp
first), so clients _can_ execute the test code.
Thanks,
Steve
More information about the Python-list
mailing list