Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap unittest method test in TestSuite #3295

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/test_plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions news/2 Fixes/3295.md
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 1 addition & 1 deletion pythonFiles/visualstudio_py_testlauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down