I have a large project that is unit tested using the Python unittest module.
I have one small method that controls large aspects of the system's behaviour. I need this method to return a fixed result when running under the UTs to give consistent test runs, but it would be expensive for me to mock this out for every single UT.
Is there a way that I can make this single method, unittest aware, so that it can modify its behaviour when running under the unittest?
I am sure that there are other, better, methods but you could always set a global flag from your main and not under unit test then access it in your method.
The other way of course would be to override the method as a part of the unit test set-up - if your method is called brian and you have a test_brian then simply during your pre-test setting brian = test_brian will do the job, you may need to put module names into the preceding statement.
How can a piece of python code tell if it's running under unittest