You can debug any code of the python app. In dev mode, any action triggered on the web interface can be debugged.
Note that running the dev server using
VsCode will activate the debugger. This is really useful to test and debug your brick but it slows the execution of the code. Either use the prod environment for real data test or run the dev server manually (without the debugger) by running the following command in a terminal in
python3 /lab/.sys/app/manage.py --runserver
This is a real VsCode running so you can find plenty information online on how to use the VsCode. for example here is the official documentation for debugging : https://code.visualstudio.com/docs/editor/debugging
One useful thing to debug are experiments. With this you can debug your tasks. In codelab open the task file you want to debug and set a breaking point in the line you want. A breaking will stop the code execution each time the program reaches the line of the breaking point.
To create a breaking point, simply click on the left of the any line number that is executable:
A small red dot should appead which mean that the breakpoint is active.
Once you breakpoint is set, the execution will stop there whenever this line is executed.
To trigger the execution, go back in the web interface and create an experiment that uses the task you want to debug. When you will run your experiment, the breakpoint shloud be activated.
Debugging section to see how to use the debugger.
With the breakpoint you can also easily debug anything like the Resource views. Simply put the breakpoint in you view code and show the view in the web interface. Your breakpoint should be activated.
To debug a test, you must open the codelab in the folder of the brick you want to test. Once the codelab opened in the correct brick there should be
Test a single fileoption to run
When you execute this, the codelab will ask you for the test file name. Enter the file name of the test you want to execute, and press Enter. If the file exists on the brick and is a test, the code should be executed and if there any breakpoint in your test file, the execution should stop there.
You can see that you reached a breakpoint on the browser codelab tab where there is a red circle.
On the codelab you should see that button of the small popup are enable
You should also see a yellow line on the current execution line and the “Call stack” section of the left that is provided with information.
You can put you mouse over any variable to see the variable values.
In the bottom section, aside the terminal tab you have a
DEBUG CONSOLE tab. This section is useful. There, you can write any python code, to see variables, update them or call function.
Finally, you can use the small popup to continue the execution of execute the code line per line.
List of breakpoints
On the bottom left of the screen, you can see the list of breakpoints :
You can disable or delete them from here.
Breakpoint on exception
By default VS code stop the code execution when an uncaught exception occurs. For exemple, when an exception occurs on a task the program will be stop on exception raise to improve debugging. You can disabled that by uncheking the check-box « Uncaught Exceptions » on the bottom left.