question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python unittest debug seems broken

See original GitHub issue

Issue Type: Bug

I am new to Python unittest, but I think this should work:

"""Unit tests for some module."""

import unittest


class TestSomething(unittest.TestCase):
    """Test with strings for now."""

    def test_MyThing(self):
        """Test thing and succeed."""
        self.assertEqual(1, 1)

    def test_Thing2(self):
        """Test thing and succeed."""
        self.assertEqual(1, 1)


if __name__ == '__main__':
    unittest.main()`

On running ‘Discover Unit Tests’, this file (test_something.py) is found and shows in the Test sidebar. On opening the file The CodeLens decorators appear. The various ‘Run Test’ commands work and the tests are shown as succeeding (I mention all this because there was lots of backtracking and trying various solutions found in GitHub issues around testing, including wiping and reinstalling the ms-python extension, to get to these parts working reliably).

When I attempt to ‘Debug Test’, a message “Could not load unit test config from launch.json” appears in the lower right and the spinners (Running Tests in bottom bar and by the test method in sidebar) are spinning. On closing the message, I drop into the debugger looking at visualstudio_py_testlauncher.py.

My reading of GitHub issues is that I should not need an entry in launch.json. Trying Add Configuration -> Python: Unit Tests adds an entry, but seems to make no difference.

From the debugger I can stop the debugger and return to the test file in a state with the spinners stopped and still able to successfully run the tests. There is another mode (perhaps the message display times out and I have not closed it to enter the debugger?) where the spinners continue, but I can stop them by editing/saving the file - but now when I Run Tests, the spinners just start again with no result. Presumably the other process is still running somewhere and I don’t see it, but it is very unintuitive at this point.

Extension version: 2019.2.5558 VS Code version: Code 1.32.3 (a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4, 2019-03-14T22:46:48.547Z) OS version: Darwin x64 18.2.0

System Info
Item Value
CPUs Intel® Core™ i5-6500 CPU @ 3.20GHz (4 x 3200)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: unavailable_off
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 3, 3, 3
Memory (System) 32.00GB (13.67GB free)
Process Argv
Screen Reader no
VM 0%

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
rob-millercommented, Mar 20, 2019

Thanks, replacing launch.json did solve the problem of the error message, and thus control is reliably returned after ‘Debug Test’ is run.

  • testing for valid json on saving this file would be a good feature, or some other way of notifying user
  • It still doesn’t seem right that Debug Test -> run to completion breaks in visualstudio_py_testlauncher.py (at line 325: sys.exit(not result.wasSuccessful()) / Exception has occurred: SystemExit /False)? Might be slightly better if that file did not replace my test file in the open tab.
0reactions
karrtikrcommented, Mar 27, 2019

Good to know! AFAIK We are currently working on the second point you mentioned. You can open up an issue for any improvements you can think of.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use %debug to investigate Python unittest failure?
Use a testrunner. I recommend you to install pytest with pytest-ipdb plugin. You should be able to run it in a similar way...
Read more >
Debugging Your Unit Test Suite in Python | Capital One
Using a debugger lets you see exactly what's broken and what's needed, ... Then I'll move to a working example of a unit...
Read more >
Python unittests cannot be debugged. Breakpoints ignored
The Python debugger seems to ignore breakpoints when attemping to debug unittests (Right click on a testcase in testexplorer, debug).
Read more >
Fighting Bugs in Python - The Data Frog
Let's see how to make sure they don't live long with debugging and unit tests. Introduction to pdb and unittest and a few...
Read more >
How to debug Docker containers! (Python + VSCode) - YouTube
I recently encountered an issue where a python unit test was passing inside of a container, but failing locally. In this video I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found