0

My code is importing several variables using os.environ. When I run 'coverage run' command for testing, it gives key error. Is there a way to provide env files to read env variables from there, or just ignoring those env variables.

This is the bash script that I am running.

#!/bin/bash
set -e
BUILD_TAG="nonprod.abc.com/$IMAGE_NAME:$BUILD_VERSION"
echo $BUILD_TAG
echo $WORKSPACE
docker run -v $WORKSPACE/tmp:/data_loader/log $BUILD_TAG \
bash -c \
'coverage run --include=/data_loader/src/* --omit=data_loader/src/groovy/* \
-m pytest --junitxml=/data_loader/log/app-pytestreports.xml && \
coverage xml --omit="data_loader/src/groovy/*" -o /data_loader/log/coverage.xml && \
coverage report --include=/data_loader/* --omit=/data_loader/src/groovy/* > /data_loader/log/coverage.txt && \
coverage html --include=/data_loader/* --omit="*/data_loader/src/groovy/*" -d /data_loader/log/app-coverage '

The command coverage rungives the following key error -

11:30:41  File "work.py", line 6, in <module>
11:30:41      logger.setLevel(os.environ['LOG_LEVEL'])
11:30:41    File "/usr/local/lib/python3.9/os.py", line 679, in __getitem__
11:30:41      raise KeyError(key) from None
11:30:41  KeyError: 'LOG_LEVEL'

Any body has any suggestions?

2
  • 1
    Could you add code please to reproduce the error? Commented Jul 12, 2024 at 6:49
  • @User051209. I have added the code Commented Jul 12, 2024 at 18:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.