Home > Software design >  How to terminate a long-running Python unittest in VSCode?
How to terminate a long-running Python unittest in VSCode?

Time:09-06

VSCode 1.71.0 on macOS 12.5.1 (Apple M1)

Python 3.10.6 in venv

I have a unittest setup, executed from within VSCode, which is running for much longer than it should (due to an inefficient algorithm in my code at present). The only way I can find to terminate the long-running task is to SIGTERM it thru top. The test is displayed as running in the Test Explorer, but it has no further control over the process

I'm looking for how I can do this via VSCode if possible. I have tried the following options:

  • Nothing available by right-click in the Test Explorer, just the start / debug options.
  • Ctrl-C in the Python test log output or in the Python output windows does nothing
  • Running as a debug session, with no breakpoints does at least offer me a stop button. Is this my best option, even though it brings the overhead of a debug session?

My fallback option is to run the tests from the CLI:

python -m unittest tests.test_file.TestMethods.test_1

where I can ctrl-c, but I'd like to be able to have the same control in the Test Explorer.

CodePudding user response:

Seems my OP was a bit of a duplicate and I have missed the obvious. Thx to @rioV8 for the clue.

enter image description here

  • Related