[py-dev] Detect whether py.test is running

Antonio Cuni anto.cuni at gmail.com
Sat Oct 16 19:05:29 CEST 2010


Hi,

I need a way to distinguish whether the current module is being imported 
because we are running the tests, of whether we are running the main program.

I know that the correct way would be to inject the information from the top, 
but I'm using a framework which relies on some global state to store the 
various options, and I have to deal with it.

Anyway, is there any official/recommended way to do it?
What I'm doing right now is this (py 1.3.1):

if py.test.config.__dict__ == {}:
     # py.test is NOT running
     ...
else:
     # py.test is running

ciao,
Anto



More information about the Pytest-dev mailing list