VSC’s Python debugger breaks exercise scripts

The debugger ‘breaks’ the file location in VSC in my shell where I am experimenting with exercise scripts - - it reverts the current working directory location to several directories above - - disrupting my CLI workflow. Am I doing something wrong? Or is this a glitch / known issue that can be fixed or is planned to be fixed? Or would this fit more so into the category of feature request?

I am not a power user of VSC for Python (I use VSC mainly for SVG, Go-lang, and mermaid diagramming), but I did find this set of instructions on how to set up a launch config json for the VSC debugger, which might help you set the path you’d like for exercises. Additionally, I found a Python debugging configurations article in the VSC docs, but don’t know if any of the configurations lists would be helpful for your curcumstance.

You can also find general debugging docs for VSC here.

I know that PyTest can be run in a mode that drops you into PDB for debugging when a test fails, but have not experimented with that particular setup outside of using it directly in a terminal shell.

So I hope some of that helps. :slight_smile:

1 Like

Thank you @BethanG.

I know it’s been 3 weeks since my last post. I’ve been procrastinating writing a proper reply until now.

Tonight I finally sat down to tackle the issue with exercism breaking my CLI environment. I was going to improve my original question and issue with an actual screencast and cross post my question to Stack Overflow to crowd source how to configure VSC for resolution, based on the configuration documentation BethanG shared. But that is no longer necessary. Instead I came up with a terrific satisfactory work around I can use.

I thought I would close the loop here with my band-aid solution, as kind of like a personal note for my future reference. Who knows, maybe it might even help someone else at some point.

Here goes - -

With my use case for the VSC debugger, here is how to reproduce the problem I previously had:

  1. In the current exercism script you’re working on, add a print() statement passing in a function and some variables that you wish to examine, (for example containing a list or whatever other argument you wish to experiment with) sourced from an assertion from relevant unit test
  2. Create breakpoint like you normally would using the Python debugger
  3. Press F5 which enters debug mode
  4. Step through each line, studying the variables and interpolated values
  5. Once the debugger exhausts the values, the exercism environment quits but then the CLI directory reverts two levels above, thus breaking the workflow because it forces you to traverse two levels back down to the right directory to continue running pytest. It gets tedious really quick, over and over.

That’s a better description of my original problem.

As inconvenient and redundant as it may be to constantly change two directory levels down after every single debug run, all I need to do is keep a separate terminal emulator window open and run the pytest command in the current CLI location I am working on. The abrupt directory disruption is only present in the integrated VSC terminal. So I can continue making changes to my script and testing with F5 as much as I need to in VSC and then just keep my $ python -m pytest unit_test.py commands in a separate terminal.

tl/dr: You can use VSC for coding and debugging and then use spearate terminals for pytests.