5

I started writing a django app with the help of pipenv.

From the CLI I run my tests via pipenv run ./manage.py test. That loads my .env-file puts me inside the virtualenv and executes the test command.

Now I want to do the same with a Run configuration in intellij.

What I did:

  • Created a new run configuration with "Django tests" base
  • "use specified interpreter" is set to my virtualenv
  • all other options are set to default

When I run the tests with that new configuration, I get errors that indicate, that DJANGO_SETTINGS_MODULE wasn't really set.

Looking further the command intellij uses for running my tests is /home/user/.virtualenvs/django-proj-wQnnAIXN/bin/python /home/user/.IntelliJIdea2017.3/config/plugins/python/helpers/pycharm/django_test_manage.py test /home/user/dev/django-proj_site

How can I tell intellij to run the tests with pipenv run .. so that my .env file is loaded?

Simon Lenz
  • 2,732
  • 5
  • 33
  • 39
  • why don't you enable the virtual environment in your project's root directory `pipenv shell`, then you just run `python manage.py test`? – lmiguelvargasf Dec 06 '18 at 18:34

1 Answers1

2

You can have IntelliJ load your .env file using the EnvFile plugin.

See the answer to IntelliJ : executing a program with environment variables stored in a separated file for more details, including how to configure the plug in.

chobok
  • 423
  • 4
  • 19