I have config.py module that loads environment variables necessary for connecting to MongoDB. When I try to run the test discovery in vscode pytest doesn't find these environment variables. In the test files, I use some methods from a module that imports the config module, so the code that reads these env vars always run.
The environment variables are defined in my .bashrc file.
Pytest alone can run the test using these environment variables if I run it from the terminal
python /home/orch/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear tests
That's the command vscode runs when activating the tests discovery tool
I expect the vs code to find the tests
the out is the following error:
tests/test_db.py:5: in <module>
from src.core.db import MongoHandler
src/core/db.py:5: in <module>
from src.core.loggers import gcl_log_event
src/core/loggers.py:8: in <module>
from configuration import config
configuration/config.py:22: in <module>
user_name = os.environ['EVO_DB_USER_NAME']
../../.local/share/virtualenvs/evolve-sjbSOQds/lib/python3.7/os.py:678: in __getitem__
raise KeyError(key) from None
E KeyError: 'EVO_DB_USER_NAME'