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.

unittest "unhandled exception in thread" after running tests

See original GitHub issue

From @dosentmatter on January 26, 2017 19:30

Environment data

VS Code version: 1.8.1 Python Extension version: 0.5.6 Python Version: 3.5.2 and 3.6.0 OS and version: macOS Sierra Version 10.12.3

Actual behavior

I am using the standard unit testing framework, unittest. After running my tests, whether they pass or not and whether I run a single test or multiple tests, I get “Unhandled exception in thread started by” after the OK or FAILED. There is nothing after the “by” it is started “by<blank>”. It does not seem like a big problem though since tests are still run.

Expected behavior

I should not get the “Unhandled exception in thread started by” message.

Steps to reproduce:

  • Create a project folder
  • Create a file called test_unit.py and put this in it:
import unittest

class TestUnit(unittest.TestCase):

    def test_unit(self):
        pass
  • run all or the single unittest with the settings.json below.
  • Test passes with OK but you get “Unhandled exception in thread started by”.

Settings

Your launch.json (if dealing with debugger issues):
none Your settings.json:

// Place your settings in this file to overwrite default and user settings.
{
    "python.unitTest.unittestEnabled": true,

    "python.unitTest.unittestArgs": [
        "-v",
        "-p",
        "test_unit*.py"
    ]
}

Logs

Output from Python output panel

test_unit (test_unit.TestUnit) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
Unhandled exception in thread started by 

Output from Console window (Help->Developer Tools menu) none

Copied from original issue: DonJayamanne/pythonVSCode#674

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:20 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brettcannoncommented, Apr 16, 2018

I’ve labeled this as a macOS issue since I can’t reproduce on Windows.

1reaction
mkj28commented, Apr 16, 2018

For my case of “Unhandled exception in thread started by” - seems to be happening when running in VSCode only for me?

test_sample.py:

import unittest
class SampleTestCase(unittest.TestCase):
    def setUp(self):
        print('TODO')
    def test_sync(self):
        print('TODO')

.vscode/settings.json:

{
    "python.unitTest.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "test_*.py"
    ],
    "python.unitTest.unittestEnabled": true
}

I get that error when running tests from VSCode but not when running this in commandline: python3 -m unittest discover -v -s . -p test_*.py

Read more comments on GitHub >

github_iconTop Results From Across the Web

unittest unhandled exception in thread after running tests #74
I am using the standard unit testing framework, unittest. After running my tests, whether they pass or not and whether I run a...
Read more >
How to handle exceptions raised in other threads when unit ...
Use BackgroundWorker to do the unit test work. BackgroundWorker will automatically catch unhandled exceptions and report them in Error property ...
Read more >
Usage and Invocations — pytest documentation
Tests were collected and run but some of the tests failed. Exit code 2. Test execution was interrupted by the user. Exit code...
Read more >
tl.testing.thread - PythonHosted.org
Thread implementation which swallows unhandled exceptions. Swallowing exceptions is useful if it is clear that they are of no interest and shall not...
Read more >
Get started with Live Unit Testing - Visual Studio
Visual Studio will rebuild the project and start Live Unit Test, which automatically runs all of your tests. When it finishes running your...
Read more >

github_iconTop Related Medium Post

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