Home > Software engineering >  "pytest" is not accessed / Import "pytest" could not be resolved - Pylance
"pytest" is not accessed / Import "pytest" could not be resolved - Pylance

Time:12-05

I haven't touched python in a long time and I forgot how much of a pain importing can be.

So I'm using pylance and pipenv as my shell. I have pytest installed in my local env, I can run pytest from the command line and test my code. However, I can't import it in the same file I'm running my tests from. Any idea what might be causing that problem?

Python version 3.9

I have my tests in a separate file right below root. I don't have a init.py file in tests. I've read that that can cause problems.

CodePudding user response:

probably Pylance is having problems with the path for site-packages folder for your virtual environment and returns Import "pytest" could not be resolved, you need to set python path in this way:

"python.pythonPath": "/my/project/path/.venv/bin/python"

CodePudding user response:

I tried h. deville fletcher's answer and it didn't seem to work for me, but I could have messed up in there too. However, in the process, I remembered that I hadn't changed my interpreter. Once I changed the interpreter to my pipenv shell that fixed my problem.

  • Related