Our travis.yml
looks like this:
language: python
python:
- "2.7"
env:
- "MONGO_URL=mongodb://localhost/"
services: mongodb
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
script: nosetests
Then in the python script with the tests, the line
server.connect(os.environ['MONGO_URL'])
throws an error (shortened):
File "/home/travis/virtualenv/python2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
This error only occurs on travis. If we run them locally, it works without a problem. So we assume we set the environment variable MONGO_URL
in a wrong way. We already tried ommitting the quotation marks, but it did not help.
Any hints? We use the free cloud service of travis-ci.
Environ and set default:With the environ dictionary variable value of the environment variable can be set by passing the key in the dictionary and assigning the value to it. With setdefault a default value can be assigned to the environment variable. Bypassing the key and the default value in the setdefault method.
To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").
It works perfectly fine now, the error was that I accidently created another travis.yml
missing the .
in front of it - so the actually executed .travis.yml
did not contain the environment variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With