File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,6 +224,31 @@ def foo():pass
224224``` python
225225import 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+
227252class 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
Original file line number Diff line number Diff line change 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 ) )
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments