title: Setting up gitlab CI with simple django project
body: <p>I have a very simple django project with a few unit tests on it and I would like to set up Gitlab to run those tests evry time I make a new commit.
  I use sqlite3 for my database (I plan to change later, but for now I want to keep it simple) and I stored some of my settings variable in a .env file.</p>
  <p>Here is my .gitlab-ci.yml file (I used the default file proposed by gitlab and removed what I thought I didn't need) :</p>
  <pre><code>image: python:latest
  
  variables:
      SECRET_KEY: &quot;this-is-my-secret-key&quot;
      DEBUG: &quot;True&quot;
      ALLOWED_HOSTS: &quot;['*']&quot;
      DB_ENGINE: &quot;django.db.backends.sqlite3&quot;
      DB_NAME: &quot;test_database.sqlite3&quot;
      STATIC_URL: &quot;/static/&quot;
  
  cache:
    paths:
      - ~/.cache/pip/
  
  before_script:
    - python -V 
    - pip install -r requirements.txt
  
  test:
    script:
      - cd backend
      - python3 manage.py makemigrations
      - python3 manage.py migrate
      - python3 manage.py test
  </code></pre>
  <p>but when I commit, I get this error</p>
  <pre><code>$ python3 manage.py makemigrations
  /usr/local/lib/python3.9/site-packages/environ/environ.py:628: UserWarning: /builds/romainros/ynoverflow/backend/ynoverflow/.env doesn't exist - if you're not configuring your environment separately, create one.
    warnings.warn(
  Traceback (most recent call last):
    File &quot;/builds/romainros/ynoverflow/backend/manage.py&quot;, line 22, in &lt;module&gt;
      main()
    File &quot;/builds/romainros/ynoverflow/backend/manage.py&quot;, line 18, in main
      execute_from_command_line(sys.argv)
    File &quot;/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 381, in execute_from_command_line
  No changes detected
      utility.execute()
    File &quot;/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py&quot;, line 375, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File &quot;/usr/local/lib/python3.9/site-packages/django/core/management/base.py&quot;, line 336, in run_from_argv
      connections.close_all()
    File &quot;/usr/local/lib/python3.9/site-packages/django/db/utils.py&quot;, line 224, in close_all
      connection.close()
    File &quot;/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py&quot;, line 248, in close
      if not self.is_in_memory_db():
    File &quot;/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py&quot;, line 367, in is_in_memory_db
      return self.creation.is_in_memory_db(self.settings_dict['NAME'])
    File &quot;/usr/local/lib/python3.9/site-packages/django/db/backends/sqlite3/creation.py&quot;, line 12, in is_in_memory_db
      return database_name == ':memory:' or 'mode=memory' in database_name
  TypeError: argument of type 'PosixPath' is not iterable
  </code></pre>
  <p>I've tried to add a <code>app.settings.ci</code> file and add <code>--settings app.settings.ci</code> in my test command, but I got this error :</p>
  <pre><code>django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
  </code></pre>
  <p>Any idea ?</p>
  <p><strong>EDIT</strong></p>
  <p>I use django-environ for my environment variables.</p>
  <p>Here are the most important parts of my settings</p>
  <pre><code># settings.py
  
  from datetime import timedelta
  
  import environ
  from pathlib import Path
  
  env = environ.Env()
  # reading .env file
  environ.Env.read_env()
  
  
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = env(&quot;SECRET_KEY&quot;)
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = env(&quot;DEBUG&quot;)
  
  ALLOWED_HOSTS = env(&quot;ALLOWED_HOSTS&quot;)
  
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'rest_framework',
      'rest_framework_simplejwt.token_blacklist',
      'api'
  ]
  
  # Database
  # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': env(&quot;DB_ENGINE&quot;),
          'NAME': BASE_DIR / env(&quot;DB_NAME&quot;),
      }
  }
  
  STATIC_URL = env(&quot;STATIC_URL&quot;)
  </code></pre>