I’m trying to set up testing with Heroku CI on a Flask app, but my tests are failing because they can’t see environment variables.
I have all these environment variables defined as config vars in Heroku. I’ve also enabled CI on Heroku. I’m surprised that app.json doesn’t automatically import the relevant config variables.
Here’s my app.json:
{
"name": "my-heroku-app-name",
"repository": "https://github.com/myorg/myrepo",
"environments": {
"test": {
"scripts": {
"test-setup": "pip install -r requirements.txt",
"test": "pytest tests"
}
}
}
}
But then the tests fail:
mytest.py:71: in <module>
assert ENVIRONMENT in ALL_ENVS
E AssertionError
(The value of the ENVIRONMENT
config var on Heroku is definitely in ALL_ENVS
, fwiw.)
I tried adding this in my app.json:
"env": {
"ENVIRONMENT": {
"required": true
},
},
But then the CI failed to run, with the following error:
Could not create test run. Invalid app.json. Config var "ENVIRONMENT" is required.
Maybe I need to specify the value of the variable somehow, but how? The Heroku docs don’t say.