0

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

5
  • 2
    Not just a different Python version, but a different operating system. I'd guess you're using WSL, and VS Code's terminal is aware of that but the testing extension isn't. Commented Oct 11, 2023 at 15:44
  • 2
    Are you using the "Connect to WSL" option in VSCode or running it straight on windows? Commented Oct 11, 2023 at 15:46
  • I`m just using the WSL Extension, is the connect to WSL different? Commented Oct 12, 2023 at 13:17
  • I am using WSL and visual code, is there a way I can make testing aware of the different versions I have been through the settings and dont see anything to set that Commented Oct 12, 2023 at 13:20
  • code.visualstudio.com/docs/remote/… Commented Oct 13, 2023 at 2:24

2 Answers 2

1

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.

enter image description here

The terminal will be affected by the system environment variables, and it will use the python environment configured in the environment variable path.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments