I have done some experimentation and you can use the VS Code Debug mode and breakpoints with the following configuration.
However, you will need to disable the caching to hit the breakpoint for some parts of the code.
1. Override the Container Command
First, override the command and the ports fields in the docker-compose file for the service you would like to test.
You can use the
docker-compose.override.yml file to achieve this, it is located at
"$(tutor config printroot)/env/dev/docker-compose.override.yml".
The command should be replaced with the following:
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./manage.py lms runserver 0.0.0.0:8000"]
The 5678 port is the debugging port and 8000 port is the default lms port. You should also replace lms with cms if you are testing the cms.
I am using
debugpy as it is the default suggestion from VS Code.
The ports should be replaced with the following:
It will look something like this in the end:
command: ["sh", "-c", "pip install debugpy -t /tmp && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./manage.py lms runserver 0.0.0.0:8000 --nothreading"]
2. Configure VS Code
You should create a
launch.json file under the
.vscode folder in your workspace root. I have the following structure, you should adjust the following configuration accordingly if you have a different structure.
- root -
- /tutor -
$(tutor config printroot)
You can use the following configuration, however, you should change the port and the localRoot if you have changed the default for any of those.
"name": "Python: Remote Attach",
3. Start Developing
You can use the familiar
tutor dev start -d lms and
tutor dev stop lms.
The LMS will not launch until the debugger is attached.
Everything above applied to CMS as well, just change lms with cms.