title: Secret Key not found when Django Unit Tests are executed
body: <p>Whenever I'm running my Django-Tests via the <code>unittests.py</code> file in the main folder the <code>SECRET KEY</code> in <code>.env</code> is not found.
  What is the correct way to set up the regular Unittests-File for a series of Django-Tests?
  I wrote my <code>settings.py</code> in a way it's able to write a new key if no other key is found:</p>
  
  <p>---<strong>settings.py</strong>---</p>
  
  <pre><code>try:
      print("Current key: " + os.environ['SECRET_KEY'])
      SECRET_KEY = os.environ['SECRET_KEY']
  except KeyError as kerr:
      logging.error("Can't find Secret Key in settings.py")
      path_env = os.path.join(BASE_DIR, '.env')
      utils.generate_secret_key(path_env)
      dotenv.read_dotenv(path_env)
      SECRET_KEY = os.environ['SECRET_KEY'] 
  </code></pre>
  
  <p>This has worked, but as on every run of the unittests another new key is created, which is not intended. So far I'm running the unittests with a default script which works fine, except for the issue with the key:</p>
  
  <p>---<strong>unittests.py</strong>---</p>
  
  <pre><code>import DjangoProject.tests_client
  suite = unittest.TestSuite()
  loader = unittest.TestLoader()
  suite.addTest(loader.loadTestsFromModule(DjangoProject.tests_client))
  </code></pre>
  
  <p>The implemented Test is not a too huge surprise:</p>
  
  <pre><code>from django.test import TestCase
  import django
  django.setup()
  
  class TestBase(TestCase):
  
      def setUp(self):
          #Stuff
  
      def tearDown(self):
          self.removeData()
  
      def test_Clienttest(self):
          #Stuff
  </code></pre>
  
  <p>The Unittests-Classes inherit as required from from <code>django.test.TestCase</code> and do what they are supposed to:</p>
  
  <p>Running the Unittest-Script with these settings will result in an error as it can't find the <code>SECRET KEY</code> (I did some debugging and indeed, the key is not loaded in the environment). For some testing I disabled the lines in the <code>settings.py</code> which create a new key and immediately get the error:</p>
  
  <pre><code>$ python3.7 unittests.py
  ERROR:root:'SECRET_KEY'
  Traceback (most recent call last):
    File "unittests.py", line 25, in &lt;module&gt;
      import DjangoProject.tests_client
    File "/home/djangohome/DjangoProject/tests_client.py", line 23, in &lt;module&gt;
      django.setup()
    File "/usr/local/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 79, in __getattr__
      self._setup(name)
    File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 66, in _setup
      self._wrapped = Settings(settings_module)
    File "/usr/local/lib/python3.7/site-packages/django/conf/__init__.py", line 176, in __init__
      raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
  django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
  </code></pre>
  
  <p>Running the test via manage.py works perfectly fine too:</p>
  
  <pre><code>$ python3.7 manage.py test DjangoProject.tests_client
  Current key: o5at!z(_()s2vbp=n4exot@gjo1==!w39uby*eju)ej#1o^lwn
  Creating test database for alias 'default'...
  System check identified no issues (0 silenced).
  ... And everything as supposed to ...
  </code></pre>
  
  <p>But how would I have to implement the run via <code>manage.py</code> in the regular Unittests so the <code>SECRET KEY</code> is loaded correctly?</p>