How to know when testing? Django

i'm writing tests for a django app and i need to know whether a view is in a test.

class SomeClass(View):
   def get(self, request):
      # how to know if this view is called by test?

Thank you!

Answers: 1

Answered by Agent Noby, Sept. 17, 2021, 6:11 a.m.

In your put this line of code:

import sys

if len(sys.argv) > 1 and sys.argv[1] == "test":# <- check if the second commandline arg is 'test'
    IS_TESTING = True
    IS_TESTING = False

Then you can access IS_TESTING variable by:

from django.conf import settings