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>I'd say if you're commenting out several parts of your code when switching between debug&amp;release mode I think <strong>you're doing wrong</strong>. Take a look for example to the <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging library</a>, as you can see, with that library you can specify the logging level you want to use only by changing a single parameter.</p>

<p>Try to avoid commenting specific parts of your debug code by having one or more variables which controls the mode (debug, release, ...) your script will run. You could also use some <a href="https://docs.python.org/3/library/constants.html#__debug__" rel="nofollow">builtin ones</a> python already provides</p>

python testing