New unittest discovery code doesn't discover all tests
See original GitHub issueRepro steps:
- Create a folder with a Python file and a
tests
folder - Inside the
tests
folder add a test filetest_something.py
(name can be anything as long as it starts withtest_
) with the following content:
import unittest
class Testing(unittest.TestCase):
def test_string(self):
a = "some"
b = "some"
self.assertEqual(a, b)
def test_boolean(self):
a = True
b = True
print("this is a test")
self.assertEqual(a, b)
class OtherTesting(unittest.TestCase):
def test_equal_string(self):
a = "some"
b = "some"
self.assertEqual(a, b)
def test_equal_boolean(self):
a = True
b = True
self.assertEqual(a, b)
class IntegerArithmeticTestCase(unittest.TestCase):
def testAdd(self): # test method names begin with 'test'
self.assertEqual((1 + 2), 3)
self.assertEqual(0 + 1, 1)
def testMultiply(self):
self.assertEqual((0 * 10), 0)
self.assertEqual((5 * 8), 40)
- In your workspace settings, make sure that testing using unittest is enabled (look for the python.testing.unittestEnabled setting and tick the checkbox), and that the value of the
python.testing.unittestArgs
setting is as follows:
[
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
]
- Use the current discovery code, notice that the unit tests under the
Testing
,OtherTesting
and `IntegerArithmeticTestCase are found - Swap to the new discovery code, notice that not all of the tests are found
⚠️ It might have something to do with some of the test names being camelCase (testMultiply
) while others are snake case (test_boolean
). Both conventions should be supported anyway. Could also be that the current discovery algorithm stops at the first testing class.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Python Unittest: No tests discovered in Visual Studio Code
To check for a potential error, click the Show Test Output , then run the tests using Run All Tests (both buttons are...
Read more >Why is Python Unittest file not discovered? - TechBrij
It is assumed you have already setup proper unit test configurations. The goal is to get exact reason why test method is not...
Read more >Quick Fix: Python Unittest not Discovering Tests - YouTube
Hopefully this video will help you solve a slightly annoying problem with python unittest where unittest will not run the tests because it ......
Read more >TestExplorer test discovery for google tests doesn't work since ...
You must clean the Unittest DLL project and rebuild the Unittest exe afterwards... only this updates the complete test list.. Click to vote...
Read more >Set up unit testing for Python code - Visual Studio
By default, Visual Studio identifies unittest and pytest tests as methods whose names start with test . To see test discovery, do the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is for you to figure out and fix 🙂
fixed: https://github.com/microsoft/vscode-python/pull/19324