A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/074403.html below:

excluding unit test code

excluding unit test code excluding unit test codeRemco Gerlich scarblac at pino.selwerd.nl
Tue Apr 3 03:01:49 EDT 2001
Steven Haryanto <steven at haryan.to> wrote in comp.lang.python:
> Since an XP-faithful coder can write lots of test suites,
> is there a simple way to exclude these code in a module
> from the production code?

A simple idiom is 

if __name__ == '__main__':
  # tests here
  
That way the scripts are run when the module is run by itself, but not when
it is imported.

Also, __debug__ is usually 1, but 0 when the -O (optimize) command line
switch is used. -O also removes assert commands. -O -O discards doc strings
as well. So you could put your tests under

if __debug__:
  # tests here

And use your production code with the -O command line option.

-- 
Remco Gerlich

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4