Skip to content

Commit a29ce05

Browse files
alexander-yud3r3kk
authored andcommitted
Wrap unittest method test in TestSuite (microsoft#3295)
1 parent 6918e8d commit a29ce05

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎.github/test_plan.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,31 @@ def foo():pass
224224
```python
225225
import unittest
226226

227+
MODULE_SETUP = False
228+
229+
230+
def setUpModule():
231+
global MODULE_SETUP
232+
MODULE_SETUP = True
233+
234+
235+
class PassingSetupTests(unittest.TestCase):
236+
CLASS_SETUP = False
237+
METHOD_SETUP = False
238+
239+
@classmethod
240+
def setUpClass(cls):
241+
cls.CLASS_SETUP = True
242+
243+
def setUp(self):
244+
self.METHOD_SETUP = True
245+
246+
def test_setup(self):
247+
self.assertTrue(MODULE_SETUP)
248+
self.assertTrue(self.CLASS_SETUP)
249+
self.assertTrue(self.METHOD_SETUP)
250+
251+
227252
class PassingTests(unittest.TestCase):
228253

229254
def test_passing(self):
@@ -247,6 +272,7 @@ class FailingTests(unittest.TestCase):
247272
- [ ] Code lens for a method runs just that test
248273
- [ ] `Run Test` works
249274
- [ ] `Debug Test` works
275+
- [ ] Module/suite setup methods are also run (run the `test_setup` method to verify)
250276

251277
#### [`pytest`](https://code.visualstudio.com/docs/python/unit-testing#_pytest-configuration-settings)
252278
```python

‎news/2 Fixes/3295.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix issue with the unittest runner where test suite/module initialization methods were not run when running a single test method.
2+
(thanks [Alex Yu](https://github.com/alexander-yu))

‎pythonFiles/visualstudio_py_testlauncher.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def main():
298298
if testId.startswith(opts.tests[0]):
299299
suite = cls
300300
if testId == opts.tests[0]:
301-
tests = m
301+
tests = unittest.TestSuite([m])
302302
break
303303
except Exception as err:
304304
errorMessage = traceback.format_exception()

0 commit comments

Comments
 (0)