I’m coding some regression tests for an API in Visual Code. I am using pytest in Python and the testing feature in Visual Studio Code. Most of my tests are fine, however I have one test which creates a virtual network but, it fails because it can’t find a certain parameter. If I run the same command manually into WSL extension terminal it runs successfully.
On investigating I noticed Testing is using a different version to Python than if I run it in the Terminal:
From the terminal:
platform linux -- Python 3.10.6, pytest-7.3.1, pluggy-1.0.0
rootdir: /mnt/c/API Testing
plugins: reraise-2.1.2
collected 1 item
From Testing:
platform win32 -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0
rootdir: c:API Testing
collected 1 item
I understand this may not cause the errors I’m seeing but I find it odd there are two different version and I don’t see a way to change the version that specifically testing uses.
Has anyone seen this before? or have any suggestions on how I can sync them up?
I have searched the settings and the settings.json file for python versions all seem to be just for the whole Visual Studio Code suite rather than just the testing area
2
Answers
I managed to fix the issue, it was @jonrsharpe comment saying they were different OS's.
for some reason it just never really occurred to me I updated python on my laptop and installed pytest it all working as expected now
The python extension will use the interpreter you choose for it, which is the one shown in the lower right corner of the interface. You can modify it via Ctrl+Shift+P –>
Python: Select Interpreter
.The terminal will be affected by the system environment variables, and it will use the python environment configured in the environment variable
path
.