Development vs Release Python Code
<p>I am currently developing a Python application which I continually performance test, simply by recording the runtime of various parts.</p>

<p>A lot of the code is related only to the testing environment and would not exist in the real world application, I have these separated into functions and at the moment I comment out these calls when testing. This requires me to remember which calls refer to test only components (they are quite interleaved so I cannot group the functionality). </p>

<p>I was wondering if there was a better solution to this, the only idea I have had so far is creation of a 'mode' boolean and insertion of If statements, though this feels needlessly messy. I was hoping there might be some more standardised testing method that I am naive of.</p>

<p>I am new to python so I may have overlooked some simple solutions. 
Thank you in advance</p>

<p>There are libraries for testing like those in the <a href="https://docs.python.org/3/library/development.html" rel="nofollow">development-section</a> of the standard library. If you did not use such tools yet, you should start to do so - they help a lot with testing. (especially <code>unittest</code>).</p>

<p>Normally Python runs programs in debug mode with <a href="https://docs.python.org/3/library/constants.html#__debug__" rel="nofollow"><code>__debug__</code></a> set to <code>True</code> (see <a href="https://docs.python.org/3/reference/simple_stmts.html#assert" rel="nofollow">docs on <code>assert</code></a>) - you can switch off debug mode by setting the command-line switches <code>-O</code> or <code>-OO</code> for optimization (see <a href="https://docs.python.org/3/using/cmdline.html#cmdoption-O" rel="nofollow">docs</a>).</p>

<p>There is something about using specifically assertions in the <a href="https://wiki.python.org/moin/UsingAssertionsEffectively" rel="nofollow">Python Wiki</a></p>

python testing