2

My test files have some explicit relative import, when i directly run debug, it will raise exception(because the exists of relative import), so i want to use -m argument when using debug mode in vscode.

I want to dubug multiple file in project_test with -m argument(this will allow me to use relative imoprt)

I have tried to modify the launch.json file, but it seems only allow me to specify a fixed module name, how can i do this?

project_test
├── log_test.py
├── user_test.py
├── other_test.py

the last two lines are my attempts.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            # "module": "project_test.log_test"  # this works correctly
            "module": "project_test.${file}"     # this will raise exception

        }
    ]
}

1 Answer 1

2

I find the following config will allow me to debug all files without specify a fixed name. The key point is to set the module path correctly.

# launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            // "module": "$('mytest.')${file}"
            "module": "project_test.${fileBasenameNoExtension}"
        }
    ]
}

More info at: https://code.visualstudio.com/docs/editor/variables-reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.