Skip to content

Debugging

mgmschoene edited this page Nov 24, 2020 · 5 revisions

Debugging

Here we explain how to connect a debugger to a test case using Visual Code IDE. It is probably very similar in other IDEs. The steps 1 and 2 are independent of the used debugger.

Step 1: Run container

In the CIT backend folder run the following command: docker-compose -f docker-compose.local.yml up -d This command starts the test_app and the dns_server.

> docker-compose -f docker-compose.local.yml up -d
Starting test_app ... 
Starting test_app ... done
Starting dns_server ... 
Starting dns_server ... done
Step 2: Start test execution

With the following command the test case is executed in depug mode. The module debugpy using port 5678 is loaded. This port of the docker container is forwarded to the same port ID of the host machine. The attribute wait-for-client is required due to the remote debugging. The end of the command described which test case gets executed (e.g. -t 9).

docker-compose -f docker-compose.driver.yml run --rm -p 5678:5678 -T driver python -m debugpy --listen 0.0.0.0:5678 --wait-for-client /driver/driver_cli.py runlocal -t 9

When this command got executed, no further output is displayed. The debugging interface is waiting for a debugger to attach.

Step 3: Attach IDE debugger

In Visual Studio Code open your test case file, e.g. case9.py. Add a breakpoint were needed. Then click Run and Debug and select Remote Attach. There proceed with the default settings (host: localhost, port: 5678). Then the test execution proceeds until the breakpoint is reached.