profile
viewpoint

Ask questionsWhen a unittest subTest fails, it says that no tests ran

Environment data

  • VS Code version: 1.33.1
  • Extension version (available under the Extensions sidebar): 2019.4.11987
  • OS and version: Ubuntu 16.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.5.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Relevant/affected Python packages and their versions: N/A

Expected behaviour

Expected to see the tests fail, and have VS Code show that it failed.

Actual behaviour

Does not indicate if the test succeeded or failed, even though the logs clearly indicate that the test was run and it failed. The status bar at the bottom of the screen says "No Tests Run". A warning notification pops up saying that no tests were run.

Steps to reproduce:

  1. Create an empty folder and open it in VS Code
  2. Create a file named test_failing_subtests.py with the contents:
import unittest
class TestFailingSubtests(unittest.TestCase):
	def test_failing_subtest(self):
		with self.subTest():
			self.fail()
	def test_failing_subtest_with_msg(self):
		with self.subTest("Placeholder message"):
			self.fail()
if __name__ == '__main__':
	unittest.main()
  1. Set up the VS Code configuration so that it discovers the test
  2. In the command palette, run Python: Discover Tests
  3. In the command palette, run Python: Run All Tests

Logs

Output for Python Test Log in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Test Log)

start
test_fail_subtests.TestFailingSubtests.test_failing_subtest
test_fail_subtests.TestFailingSubtests.test_failing_subtest_with_msg
test_failing_subtest (test_fail_subtests.TestFailingSubtests) ... test_failing_subtest_with_msg (test_fail_subtests.TestFailingSubtests) ... 
======================================================================
FAIL: test_failing_subtest (test_fail_subtests.TestFailingSubtests) (<subtest>)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/vscode-python-subtest-bug/test_fail_subtests.py", line 7, in test_failing_subtest
    self.fail()
AssertionError: None

======================================================================
FAIL: test_failing_subtest_with_msg (test_fail_subtests.TestFailingSubtests) [Placeholder message]
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/vscode-python-subtest-bug/test_fail_subtests.py", line 11, in test_failing_subtest_with_msg
    self.fail()
AssertionError: None

----------------------------------------------------------------------
Ran 2 tests in 0.001s

FAILED (failures=2)

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

[Extension Host] Python Extension: Cached data exists ActivatedEnvironmentVariables, /tmp/vscode-python-subtest-bug
console.ts:134 [Extension Host] Python Extension: getActivatedEnvironmentVariables, Class name = S, Arg 1: <Uri:/tmp/vscode-python-subtest-bug>, Arg 2: undefined, Arg 3: undefined
console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, /tmp/vscode-python-subtest-bug
console.ts:134 [Extension Host] Python Extension: Cached data exists ActivatedEnvironmentVariables, /tmp/vscode-python-subtest-bug
console.ts:134 [Extension Host] Python Extension: getActivatedEnvironmentVariables, Class name = S, Arg 1: <Uri:/tmp/vscode-python-subtest-bug>, Arg 2: undefined, Arg 3: undefined
console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, /tmp/vscode-python-subtest-bug

I'd be happy to take a stab at fixing this if somebody could point me in the right direction.

microsoft/vscode-python

Answer questions luabud

It seems that the issue could be that we don't support subTest() for test discovery. PRs to address this would be very welcome! 😊

useful!

Related questions

Auto Scroll in the Jupyter output hot 3
Workspace contains pipfile but pipenv --venv failed hot 2
Can you turn off the Microsoft Python Language Server? hot 2
Unable to debug Python tests (duplicate entries in &#34;env&#34;) hot 2
Jupyter server crashed. Unable to connect. Cannot assign requested address hot 2
Auto Scroll in the Jupyter output hot 2
Unable to run launch targets with newest VS Code Python extension hot 2
Unable to start jupyter python interactive window hot 1
HBox output is not shown correctly in the interactive window hot 1
Debug -> Add Debug Configuration 'Cannot read property openConfigFile' hot 1
VSCode cannot connect to jupyter server; with browser this works fine hot 1
Linux arm64/aarch64 support hot 1
Add setting to disable icon for "Run Python File In Terminal" hot 1
Extension Host keeps crashing hot 1
Activate environment before debugging tests hot 1
Github User Rank List