mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
run-tests: support setUp() and tearDown() in TestCase wrapper
unittest.TestCase.run() calls setUp() and tearDown() during run(). We emulate that implementation.
This commit is contained in:
parent
ed53d7b15f
commit
ecba404b77
@ -377,6 +377,9 @@ class Test(object):
|
||||
if self._threadtmp and not self._options.keep_tmpdir:
|
||||
shutil.rmtree(self._threadtmp, True)
|
||||
|
||||
def setUp(self):
|
||||
"""Tasks to perform before run()."""
|
||||
|
||||
def run(self):
|
||||
"""Run this test instance.
|
||||
|
||||
@ -506,6 +509,9 @@ class Test(object):
|
||||
|
||||
return res
|
||||
|
||||
def tearDown(self):
|
||||
"""Tasks to perform after run()."""
|
||||
|
||||
def _run(self, testtmp, replacements, env):
|
||||
# This should be implemented in child classes to run tests.
|
||||
return self._skip('unknown test type')
|
||||
@ -1351,6 +1357,15 @@ class TestRunner(object):
|
||||
# Need to stash away the TestResult since we do custom things
|
||||
# with it.
|
||||
def run(self, result):
|
||||
try:
|
||||
t.setUp()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
return
|
||||
|
||||
success = False
|
||||
try:
|
||||
self.runTest()
|
||||
except KeyboardInterrupt:
|
||||
@ -1366,6 +1381,17 @@ class TestRunner(object):
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
else:
|
||||
success = True
|
||||
|
||||
try:
|
||||
t.tearDown()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
success = False
|
||||
|
||||
if success:
|
||||
result.addSuccess(self)
|
||||
|
||||
def runTest(self):
|
||||
|
Loading…
Reference in New Issue
Block a user