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
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