{"action":"created","issue":{"url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/497","labels_url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/497/labels{/name}","comments_url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/497/comments","events_url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/497/events","html_url":"https://github.com/jorgenschaefer/elpy/issues/497","id":57585750,"number":497,"title":"set environment variables before running tests?","user":{"login":"ChillarAnand","id":4463796,"avatar_url":"https://avatars.githubusercontent.com/u/4463796?v=3","gravatar_id":"","url":"https://api.github.com/users/ChillarAnand","html_url":"https://github.com/ChillarAnand","followers_url":"https://api.github.com/users/ChillarAnand/followers","following_url":"https://api.github.com/users/ChillarAnand/following{/other_user}","gists_url":"https://api.github.com/users/ChillarAnand/gists{/gist_id}","starred_url":"https://api.github.com/users/ChillarAnand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChillarAnand/subscriptions","organizations_url":"https://api.github.com/users/ChillarAnand/orgs","repos_url":"https://api.github.com/users/ChillarAnand/repos","events_url":"https://api.github.com/users/ChillarAnand/events{/privacy}","received_events_url":"https://api.github.com/users/ChillarAnand/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jorgenschaefer/elpy/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/jorgenschaefer/elpy/milestones/14","labels_url":"https://api.github.com/repos/jorgenschaefer/elpy/milestones/14/labels","id":928225,"number":14,"title":"v1.8","description":"","creator":{"login":"jorgenschaefer","id":2500270,"avatar_url":"https://avatars.githubusercontent.com/u/2500270?v=3","gravatar_id":"","url":"https://api.github.com/users/jorgenschaefer","html_url":"https://github.com/jorgenschaefer","followers_url":"https://api.github.com/users/jorgenschaefer/followers","following_url":"https://api.github.com/users/jorgenschaefer/following{/other_user}","gists_url":"https://api.github.com/users/jorgenschaefer/gists{/gist_id}","starred_url":"https://api.github.com/users/jorgenschaefer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorgenschaefer/subscriptions","organizations_url":"https://api.github.com/users/jorgenschaefer/orgs","repos_url":"https://api.github.com/users/jorgenschaefer/repos","events_url":"https://api.github.com/users/jorgenschaefer/events{/privacy}","received_events_url":"https://api.github.com/users/jorgenschaefer/received_events","type":"User","site_admin":false},"open_issues":34,"closed_issues":16,"state":"open","created_at":"2015-01-09T08:02:23Z","updated_at":"2015-02-13T11:03:41Z","due_on":"2015-04-30T22:00:00Z","closed_at":null},"comments":1,"created_at":"2015-02-13T11:01:04Z","updated_at":"2015-02-13T11:13:54Z","closed_at":null,"body":"To run tests from terminal, I source environment variables `source .env` & run `py.test` which runs test suite. \r\n\r\nBut when I run tests from elpy(`C-c C-t`), I get lots of errors as environment variables are not available.\r\n\r\nIs there a way to source environment variables before running tests?"},"comment":{"url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/comments/74238790","html_url":"https://github.com/jorgenschaefer/elpy/issues/497#issuecomment-74238790","issue_url":"https://api.github.com/repos/jorgenschaefer/elpy/issues/497","id":74238790,"user":{"login":"jorgenschaefer","id":2500270,"avatar_url":"https://avatars.githubusercontent.com/u/2500270?v=3","gravatar_id":"","url":"https://api.github.com/users/jorgenschaefer","html_url":"https://github.com/jorgenschaefer","followers_url":"https://api.github.com/users/jorgenschaefer/followers","following_url":"https://api.github.com/users/jorgenschaefer/following{/other_user}","gists_url":"https://api.github.com/users/jorgenschaefer/gists{/gist_id}","starred_url":"https://api.github.com/users/jorgenschaefer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorgenschaefer/subscriptions","organizations_url":"https://api.github.com/users/jorgenschaefer/orgs","repos_url":"https://api.github.com/users/jorgenschaefer/repos","events_url":"https://api.github.com/users/jorgenschaefer/events{/privacy}","received_events_url":"https://api.github.com/users/jorgenschaefer/received_events","type":"User","site_admin":false},"created_at":"2015-02-13T11:13:54Z","updated_at":"2015-02-13T11:13:54Z","body":"In general, I'd recommend adding the `source .env` part to virtualenvwrapper hooks so the environment is available whenever you activate the virtualenv. For example, I use this `~/.virtualenvs/postactive`:\r\n\r\n```sh\r\n#!/bin/bash                                                                     \r\n# This hook is run after every virtualenv is activated.                         \r\n\r\nif [ -f \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\" ]\r\nthen\r\n    if [ -f \"$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")/.env\" ]\r\n    then\r\n        set -a\r\n        . \"$(cat \"$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME\")/.env\"\r\n        set +a\r\n    fi\r\nfi\r\n```\r\n\r\nThis will source and export any environment variables in an .env file in the virtualenvwrapper project directory (set with `setvirtualenvproject`) whenever it is activated. `pyvenv-workon` will detect the environment changes and export them back to Emacs.\r\n\r\nAlternatively, you might be able to set `elpy-test-pytest-runner-command` to `(\"source\" \".env\" \"&&\" \"py.test\")` – you might have to adjust the path to the `.env` file."}}