Tutorial: Attaching Visual Studio Code to Devstack LMS Container

@viadanna Have you tried debugging an individual unit test with VS Code for the LMS? I’m able to run the pytest lms/<path>/test_*.py successfully, however, I’m not able to debug to see why that test is failing. Any advice on how to do this with VS Code?

Running LMS and Studio Tests

Hey @Zachary_Trabookis

To be honest, I never invested the time for debugging tests in VSCode given the current issues we are facing.

I usually resort to

$ pytest -x --pdb <test_file>

ref.

Thanks for the response @viadanna. Yeah I’m resorting to pytest <test_file> too. Thanks for the optional parameters you mentioned above.

Maybe one day someone will figure out how to run tests within VS Code but that edX command pytest works for now along with pdb.

PTVSD has an issue with the address being in use if you restart:

So instead of normal attach, we can use this,

Thanks a lot for the solution to our woes @farhaanbukhsh :clap::clap::clap:

I can confirm it works when replacing the original code in private.py with

import os
import ptvsd

if os.environ.get('RUN_MAIN') or os.environ.get('WERKZEUG_RUN_MAIN'):
    ptvsd.enable_attach(address=('0.0.0.0', 5678), redirect_output=True)

I’ve updated the original blog post that originated this at https://opencraft.com/blog/tutorial-attaching-visual-studio-code-to-devstack-lms-container/