Skip to content

Debugging

zeyus edited this page Dec 12, 2022 · 5 revisions

Docker Dev

Flask

You can attach to the debugging service in the docker image listening on port 5678

Simply add the following to your VSCode launch.json:

    ...
    "configurations": [
         ...
        {
            "name": "NLP4All Docker: dev debug",
            "type": "python",
            "request": "attach",
            "justMyCode": false,
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}/",
                    "remoteRoot": "/usr/src/app"
                }
            ],
            "port": 5678,
            "host": "127.0.0.1"
        },
        ...
    ]
...

Local

Flask

For debugging flask with VSCode, you simply need to add the following debugging configuration to your launch.json:

    ...
    "configurations": [
         ...
         {
            "name": "NLP4ALL: App",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "nlp4all",
                "FLASK_DEBUG": "1"
            },
            "args": [
                "--no-debug",
                "run"
            ],
            "jinja": true,
            "justMyCode": false
        },
        ...
    ]
...

The "justMyCode": false property can be set to true in order to ignore module code, but note that breakpoints set in module files will not be triggered.

Pytest

As above, you can easily debug pytest tests by adding the following to your VSCode launch.json

...
    "configurations": [
         ...
         {
            "name": "Debug pytest tests",
            "type": "python",
            "request": "launch",
            "module": "pytest",
            "args": [
                "-vv",
                "-s"
            ],
            "justMyCode": false,
            "env": {
                "_PYTEST_RAISE": "1"
            },
        },
        ...
    ]
...

You can also change the "args" property and add additional args such as "-m", "data" to only run tests marked with the data pytest mark.

Clone this wiki locally