skip to Main Content

I currently run code for a project I’m working on with python using the following example command line in my workspace folder for the project.
python -m testing.test_file

This is because my project files are setup something like this;

    project_folder
    ├───src
    |   ├───__init__.py
    │   ├───main_class.py
    |   └───utils.py
    |
    └───testing
        ├───__init__.py
        ├───test_file.py
        └───main.py

and src file contains various python files that are imported in main.py and test_file.py for example.

I have tried modifying the vscode launch.json file by changing program to ${workspacefold} and adding the args "-m testing.test_file" but it always either can’t find the file or runs it can find the imports because it is running from wrong directory.

While it is fine running it using the simple command line I use currently, I wanted to try to get it working with the debugger in vscode etc rather than print debuging.

2

Answers


  1. Chosen as BEST ANSWER

    If anyone was curious, the solution I ended up using was a launch.json environment file which looked like this;

    
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "python",
                "request": "launch",
                "program": "",
                "console": "integratedTerminal",
                "args": ["-m", "${relativeFileDirname}.${fileBasenameNoExtension}"],
                "cwd": "${workspaceFolder}"
            },
        ]
    }
    
    

  2. You could try to add a .env file including the PYTHONPATH under your workspace.

    Then add "python.envFile": "${workspaceFolder}/.env", to your settings.json.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search