How can I source a bash script that contains exports for environment variables?
env.sh
...
export VARIABLE=test
...
test_file.py
...
os.environ['VARIABLE'] # Throws KeyError
...
How can I use pre-commit to run env.sh
to setup an environment that the following pytest
hook can use?
- repo: local
hooks:
- id: tests
name: run tests
entry: pytest -v
language: system
types: [python]
entry: source env.sh && pytest -v
? – MuimuirExecutable 'source' not found
– Terretentry: . env.sh && pytest -v
? – Muimuirentry: sh env.sh && pytest -v
the commit passes but no tests run – Terretentry: sh -c ". env.sh && pytest -v"
– Muimuirpre-commit
itself doesn't use shells at all, but you can useentry: bash -c '...'
orentry: sh -c '...'
-- another option is to look at pytest-env – Brilliance