From 7df4c406553af006acce0416bd41334732d3f04a Mon Sep 17 00:00:00 2001 From: Alex Yu Date: Fri, 9 Nov 2018 21:59:56 -0500 Subject: [PATCH 1/3] Wrap unittest method test in TestSuite --- pythonFiles/PythonTools/visualstudio_py_testlauncher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/PythonTools/visualstudio_py_testlauncher.py b/pythonFiles/PythonTools/visualstudio_py_testlauncher.py index f68cc2ee5a88..11fa053baaf0 100644 --- a/pythonFiles/PythonTools/visualstudio_py_testlauncher.py +++ b/pythonFiles/PythonTools/visualstudio_py_testlauncher.py @@ -298,7 +298,7 @@ def main(): if testId.startswith(opts.tests[0]): suite = cls if testId == opts.tests[0]: - tests = m + tests = unittest.TestSuite([m]) break except Exception as err: errorMessage = traceback.format_exception() From 1d615d5303d5c492789e3a50c8e624d9054dc488 Mon Sep 17 00:00:00 2001 From: Alex Yu Date: Sat, 24 Nov 2018 21:44:05 -0500 Subject: [PATCH 2/3] update test plan --- .github/test_plan.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.github/test_plan.md b/.github/test_plan.md index b7985ba004dd..98436a408791 100644 --- a/.github/test_plan.md +++ b/.github/test_plan.md @@ -224,6 +224,31 @@ def foo():pass ```python import unittest +MODULE_SETUP = False + + +def setUpModule(): + global MODULE_SETUP + MODULE_SETUP = True + + +class PassingSetupTests(unittest.TestCase): + CLASS_SETUP = False + METHOD_SETUP = False + + @classmethod + def setUpClass(cls): + cls.CLASS_SETUP = True + + def setUp(self): + self.METHOD_SETUP = True + + def test_setup(self): + self.assertTrue(MODULE_SETUP) + self.assertTrue(self.CLASS_SETUP) + self.assertTrue(self.METHOD_SETUP) + + class PassingTests(unittest.TestCase): def test_passing(self): @@ -247,6 +272,7 @@ class FailingTests(unittest.TestCase): - [ ] Code lens for a method runs just that test - [ ] `Run Test` works - [ ] `Debug Test` works + - [ ] Module/suite setup methods are also run (run the `test_setup` method to verify) #### [`pytest`](https://code.visualstudio.com/docs/python/unit-testing#_pytest-configuration-settings) ```python From a58a316e5bb3d5c59ee166606585ff57b052969c Mon Sep 17 00:00:00 2001 From: Alex Yu Date: Sat, 24 Nov 2018 22:48:15 -0500 Subject: [PATCH 3/3] add news entry --- news/2 Fixes/3295.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/2 Fixes/3295.md diff --git a/news/2 Fixes/3295.md b/news/2 Fixes/3295.md new file mode 100644 index 000000000000..12c3b5718a99 --- /dev/null +++ b/news/2 Fixes/3295.md @@ -0,0 +1,2 @@ +Fix issue with the unittest runner where test suite/module initialization methods were not run when running a single test method. +(thanks [Alex Yu](https://github.com/alexander-yu))