Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest "unhandled exception in thread" after running tests #78

Closed
DonJayamanne opened this issue Nov 13, 2017 · 20 comments
Closed

unittest "unhandled exception in thread" after running tests #78

DonJayamanne opened this issue Nov 13, 2017 · 20 comments
Assignees
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug macos

Comments

@DonJayamanne
Copy link

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". 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

@DonJayamanne
Copy link
Author

From @tomhunter-gh on February 5, 2017 22:38

I am getting the same or very similar. On the first go I am able to debug tests but I can't debug a second time without restarting VSCode. Not much of an error, just

----------------------------------------------------------------------
Ran 1 test in 0.752s

OK
Unhandled exception in thread started by 
READY

The status bar has the exclamation mark and "Running Tests" and spinner spinning forever..

Visual Studio Code
Version 1.9.0
Commit 27240e71ef390bf2d66307e677c2a333cebf75af
Date 2017-02-02T08:31:00.827Z
Shell 1.4.6
Renderer 53.0.2785.143
Node 6.5.0

VSCode Python extension version 0.5.8
Python 3.6 (Anaconda)
Windows 10 (latest - "device up to date")

@DonJayamanne
Copy link
Author

From @dosentmatter on February 6, 2017 6:36

I also tested the debug all/single test(s) but this was a couple days back so I don't remember the specifics. It always worked on the first go and I was able to get to a breakpoint. On the next tries, it would be stuck on running tests, never get to the breakpoint, and does not show the debug buttons (continue, step into, step over, etc.). This is similar to what @tomhunter-gh said.

If I keep trying to cancel the currently debug test that is running by starting another debug, it would eventually work sometimes. Though it's not clear when and why it would sometimes work.

@DonJayamanne
Copy link
Author

From @tomhunter-gh on February 6, 2017 20:36

I noticed that if I debug a test (using the hyperlink above method name) and then when I'm stopped on a breakpoint hit the restart button, I get the following error message:

There was an error in starting the debug server. Error = {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":3000}

I also noticed that the test / debug hyperlinks don't appear when you open VSCode if the test file is open (due to file being open in last session and restored) - you have to close the file and re-open to get the hyperlinks to appear. Update: actually you can just switch to another editor and then back again and the hyperlinks appear, but they don't appear if the file is re-opened automatically on startup from previous session.

@DonJayamanne
Copy link
Author

From @tomhunter-gh on February 6, 2017 21:6

I also noticed that I get the following error in the Python Test Log on startup after it lists out the tests in my project:

C:\Users\tomhu\Anaconda3\lib\site-packages\IPython\html.py:14: ShimWarning: The IPython.html package has been deprecated. You should import from notebook instead. IPython.html.widgets has moved to ipywidgets.
"IPython.html.widgets has moved to ipywidgets.", ShimWarning)

@DonJayamanne
Copy link
Author

From @RAbraham on May 13, 2017 17:28

What I have discovered from trial and error is:

  1. If I keep the suggested settings below, Run All Unit Tests works but not clicking on the Run Test visual button above each test. I get No tests ran, please check the configuration settings for the tests.
 "python.unitTest.unittestArgs": [
        "-v",
        "-s",
        ".",
        "-p",
        "*test*.py"
    ]

When I changed the . above to explicitly point to my tests i.e ${workspaceRoot}/myproject/tests, the visual Run Test above each test worked for me.

It would be nice if I could just specify ${workspaceRoot} and the unittest framework would recursively find my tests for me.

And.. thank you for your work on this plugin :)

@DonJayamanne
Copy link
Author

From @BlacKCaT27 on June 16, 2017 3:45

Is there any update on this? I'm seeing this same issue and it's making it rather hard to use VS Code to manage unit tests.

What I've observed is that whatever is breaking, is breaking part of the UI in VS Code involving the "At a glance" test results in the status bar on the bottom of the screen.

For example, in my project I have 50 unit tests. If all of them pass, I see the green "✔ 50" in the status bar, but nothing else. If one of my tests fails, I only see the green checkmark and some value representing all the tests that passed before that test failed. It does not appear to run additional tests even though I have fail-fast turned off. But I don't see anything in the status bar relating to the number of failed or un-run tests.

In the "Python Test Log" output window, I see:


Ran 50 tests in 0.335s

OK
Unhandled exception in thread started by

At the end of my test results when all tests pass. On a failure, I see:

test_assert () ... FAIL
Unhandled exception in thread started by

If I check the developer tools console output, I see:

[Extension Host] Error: read ECONNRESET extensionHost.ts:293

Which in viewing the source, shows me this statement erroring in the logExtensionHostMessage method:

	// Send to local console unless we run tests from cli
	if (!this.isExtensionDevelopmentTestFromCli) {
		console[logEntry.severity].apply(console, consoleArgs);
	}

Really hope there's a simple fix here somewhere. I don't know VS Code extension code well enough to have time to make a PR, but if you need any more information please let me know.

@DonJayamanne
Copy link
Author

For example, in my project I have 50 unit tests. If all of them pass, I see the green "✔ 50" in the status bar, but nothing else. If one of my tests fails, I only see the green checkmark and some value representing all the tests that passed before that test failed.

Apologies for never getting back on this.
All the output of the unit tests are displayed in the Python Test Log output panel (this is displayed at the bottom along with other output panels such as Tasks, Git, etc.

@DonJayamanne
Copy link
Author

@BlacKCaT27 please let me know if this has been resolved.
@dosentmatter are you still experiencing this issue?

@DonJayamanne
Copy link
Author

From @dosentmatter on October 31, 2017 5:47

@DonJayamanne, I still have the same problem. In the image, see "Unhandled exception in thread started by".
This happens if I click "Run Test" or if I click the green check mark on the bottom left > "Run All Tests". The tests are run but I'm not sure what's causing that error message.
image

@andresgaragiola
Copy link

I have the same issue when I press "Run Test", the test runs but the same error is showed "Unhandled exception in thread started by". On the other hand when I try to debug a test, no debug session starts.

@midemarc
Copy link

It seems specific to the mac version.

On Mac OS 10.9.5, VS Code 1.18.1, Python extension 0.9.0, Python 3.6.0, I get the error but on Ubuntu 16.0.4, VS Code 1.18.1, Python extension 0.9.0, Python 3.6.3, it works just fine.

@usrbinsam
Copy link

Same issue on Windows 10.

  • Python 3.6.4 (virtualenv)
  • VS Code
    • Version 1.19.1
    • Commit 0759f77bb8d86658bc935a10a64f6182c5a1eeba
    • Date 2017-12-19T09:46:23.884Z
    • Shell 1.7.9
    • Renderer 58.0.3029.110
    • Node 7.9.0
    • Architecture x64
    • Python Extension 0.9.1

My project structure:

├───clients
│       uploader.py
│
└───tests
    │   __init__.py
    │
    └───clients
            test_uploader.py
            __init__.py

Workspace settings for unittest:

    "python.unitTest.unittestEnabled": true,
    "python.unitTest.unittestArgs": [
        "-v",
        "-t",
        "."
    ]

Python: Run All Unit Tests works. The Run Test and Debug Test inline hyperlinks above the test functions just says "No tests ran, please check configuration settings for the tests."

From the developer tools console:

[Extension Host] Error: read ECONNRESET  (console.ts:123)
%c[Extension Host] %c(node:13616) DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
%c[Extension Host] %c(node:13616) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

Works fine when invoking unittest from the command-line as:
python -m unittest discover -v -t . -s tests
(-s switch is used here but not in Workspace Settings because my tests don't get discovered when called from VS code, maybe this is related?)

I do not have this problem when using the PyTest module instead.

@felipegmarques
Copy link

Same problem on Mac OS X 10.11.6 and VS Code 1.20.1 and Python Ext 2018.2.1

@ayrtonmassey
Copy link

ayrtonmassey commented Apr 7, 2018

I managed to fix this on my box. Turns out vscode configured a settings.json in the ./.vscode folder of my workspace with the following content:

"python.unitTest.pyTestEnabled": false,
"python.unitTest.unittestEnabled": true,
"python.unitTest.nosetestsEnabled": false,
"python.pythonPath": "${workspaceFolder}\\venv\\Scripts\\python.exe",
"python.unitTest.unittestArgs": [
    "-v",
    "-s",
    "./server",
    "-p",
    "test_*.py"
]

when I unittest from the command line with these arguments:

python -m unittest -v -s "./server" -p "test_*.py"

I get the following error:

usage: python.exe -m unittest [-h] [-v] [-q] [--locals] [-f] [-c] [-b]
                              [tests [tests ...]]
python.exe -m unittest: error: unrecognized arguments: -s

It looks like the default command line arguments configured by vscode are invalid. You should try deleting any values set for python.unitTest.unittestArgs in your workspace or global settings.json:

"python.unitTest.pyTestEnabled": false,
"python.unitTest.unittestEnabled": true,
"python.unitTest.nosetestsEnabled": false,
"python.pythonPath": "${workspaceFolder}\\venv\\Scripts\\python.exe",
"python.unitTest.unittestArgs": [
]

After deleting the command line arguments in settings.json I was able to run unit tests via vscode.

@brettcannon
Copy link
Member

brettcannon commented Apr 9, 2018

@ayrtonmassey that's because the -s argument is for unittest discover (keep scrolling down in the output for python -m unittest -h).

@ayrtonmassey
Copy link

Then vscode shouldn't be including -s as part of its default unittest configuration (the one you get if you follow the setup wizard).

When I include the default arguments as above, I get both the:

  • "No tests ran, please check configuration settings for the tests."
  • "Unhandled exception in thread started by"

errors. When I removed the arguments in settings.json these errors immediately stopped occurring.

Not sure what the purpose of #1341 is since my response is directly related to this issue (#74).

@brettcannon brettcannon changed the title unittest unhandled exception in thread after running tests unittest "unhandled exception in thread" after running tests Apr 11, 2018
@brettcannon
Copy link
Member

For the "Unhandled exception in thread started by" problem, can someone upload a sample project? I'm unable to reproduce based on the descriptions people have provided.

For all other issues, please open a separate issue as some people have asked about test discovery which is separate (and unittest is rather finicky about).

@brettcannon brettcannon added info-needed Issue requires more information from poster and removed needs verification labels Apr 11, 2018
@mkj28
Copy link

mkj28 commented 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

@brettcannon
Copy link
Member

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

@brettcannon brettcannon added needs verification and removed info-needed Issue requires more information from poster labels Apr 16, 2018
@DonJayamanne
Copy link
Author

Closing as a duplicate of #1529

@DonJayamanne DonJayamanne self-assigned this May 3, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug macos
Projects
None yet
Development

No branches or pull requests

8 participants