-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
set environment variables before running tests? #497
Comments
In general, I'd recommend adding the #!/bin/bash
# This hook is run after every virtualenv is activated.
if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]
then
if [ -f "$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")/.env" ]
then
set -a
. "$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME")/.env"
set +a
fi
fi This will source and export any environment variables in an .env file in the virtualenvwrapper project directory (set with Alternatively, you might be able to set |
I have added postactivate hook. In terminal, it is working fine.
In emacs, it is unable to fetch. I tried running it with/without restarting rpc after activating virtualenv.
Is there a way to make sure that variables are exported? |
Does |
no, its returning |
Then pyvenv is not seeing the environment variable changes you configured in the postactivate hook. Does Can the Python interpreter pointed to by |
|
What version of virtualenvwrapper is that? |
I was using In terminal |
emacs
but it doesn't have any variables related to venv wrapper? |
Hm. The newer versions of virtualenvwrapper seem to export fewer variables, which is a bit annoying. As a temporary solution, export But this is a but in pyvenv, I'll look into it. Thanks! |
Thank You Very Much! |
Could you upgrade to pyvenv 1.6 and see if that fixes this problem? |
upgraded to 1.6. still unable to access env variables. (getenv "DJANGO_SETTINGS_MODULE") - nil |
But the virtualenv is activated, so
|
After No, no virtualenvwrapper hook output buffer Contents of foo.txt
|
Thank you.
Apparently, virtualenvwrapper requires I just set up a local virtualenv with virtualenvwrapper 4.3.2. This does export When you are in a shell, does If yes (shot in the dark), are you using Mac OS X and are starting Emacs from the desktop and not the terminal? |
i am using ubuntu & starting emacs from launcher NOT terminal. |
oh.. thank you very much. if i start emacs from terminal, its working 👯 |
Nice! Ok. So the problem is that you do not actually load virtualenvwrapper in the environment Emacs is running in. You can fix that by setting the environment variables virtualenvwrapper requires manually, e.g. in your .emacs: (let ((workon-home (expand-file-name "~/.virtualenvs/")))
(setenv "WORKON_HOME" workon-home)
(setenv "VIRTUALENVWRAPPER_HOOK_DIR" workon-home)) I'll see if I can add this as a feature to pyvenv, thank you for the patience in tracking this down! |
sorry to bother again. i have added above lines in config & looks like there is one more issue. see env variables
previously when i said it was working, i have started terminal, activated venv & then restarted emacs. may be it was getting env variables from terminal |
As
|
when started from terminal pyvenv-virtualenvwrapper-python is "/home/k3/.virtualenvs/pearl/bin/python" but when started from launcher it is "/usr/bin/python"
there is no contents of
|
looks like
|
This uses the value of the environment variable |
thank you :) |
You're welcome, glad it works :-) |
I had the same problem where I wanted to set DJANGO_SETTINGS_MODULE and couldn't figure out how to get it to set through pre/postactivate scripts in a virtual environment, the only thing that really seemed to work for me was to set DJANGO_SETTINGS_MODULE before launching emacs. For my use it was simpler to just set the DJANGO_SETTINGS_MODULE in the manage.py script created by django then set elpy-test-django-runner-command to ("./manage.py" "test" "--noinput") |
To run tests from terminal, I source environment variables
source .env
& runpy.test
which runs test suite.But when I run tests from elpy(
C-c C-t
), I get lots of errors as environment variables are not available.Is there a way to source environment variables before running tests?
The text was updated successfully, but these errors were encountered: