i'm writing tests for a django app and i need to know whether a view is in a test.
# views.py class SomeClass(View): def get(self, request): # how to know if this view is called by test?
settings.py put this line of code:
import sys if len(sys.argv) > 1 and sys.argv == "test":# <- check if the second commandline arg is 'test' IS_TESTING = True else: IS_TESTING = False
Then you can access
IS_TESTING variable by:
from django.conf import settings print(settings.IS_TESTING)