Python: pytest test explorer not reading variables in .env

I have a python 3.10 project where I am using pyenv-virtualenv for my virtual environment.
There is an environment variable that I set to get around this issue, basically it is DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib that allows me to access brew-installed shared libararies when running locally.
I have this set in the .env file and everything

I am using pytest for unit testing and when I try to use the Test Explorer in the sidebar I get an importError for the shared library I am trying to access. When running pytest in the terminal, it works fine.

And the test explorer in VS Code works fine for the same directory. Removing the variable from .env causes the same error to appear in both IDE’s.

Am I doing something wrong or is there any reason why Cursor’s test explorer might not be able to load the environment variables in .env?

1 Like