VScode testing fails when using the debugger in conjunction with a virtual environment

25 views Asked by At

I have an odd problem, but I can't be the first.

Using VScode, I typically create a virtual environment for my Python projects. When using unit tests, the testing extension discovers and runs these tests perfectly. However, if I attempt to debug these tests through the testing extension, then the imports fail. See below:

Import failure

If I create a project without a virtual environment, then I have no problems, except of course not having a virtual environment...

For reference, the debugging I am referring to is illustrated below:

Debugging tool

I'm assuming the problem lies in my launch or settings files, which are as follows:

launch,json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {"name":"Python Debugger: Current       
     "program": "${file}"
        }
    ]
}`

settings.json:

{
    "python.testing.unittestArgs": [
        "-v",
        "-s",
        "./tests",
        "-p",
        "test*.py"
    ],
    "python.testing.pytestEnabled": false,
    "python.testing.unittestEnabled": true,
    "python.testing.cwd": "C:/PersonalProjects/CFScenarios",
    "python.terminal.activateEnvInCurrentTerminal": true}`

Any ideas?

I treid numerous iterations of changing the cwd, but to no avail. googling the error gave no joy either.

0

There are 0 answers