Expand functionality of our base TestCase classes

This commit is contained in:
Jean-Paul Calderone 2019-03-07 15:04:37 -05:00
parent 8593bf1b1c
commit 565616dc75

View File

@ -1,4 +1,9 @@
import os, random, struct
import tempfile
from tempfile import mktemp
from functools import partial
from unittest import case as _case
import treq
from zope.interface import implementer
@ -845,11 +850,32 @@ class _TestCaseMixin(object):
* Each test method will be run in a unique Eliot action context which
identifies the test and collects all Eliot log messages emitted by that
test (including setUp and tearDown messages).
* trial-compatible mktemp method
* unittest2-compatible assertRaises helper
"""
@eliot_logged_test
def run(self, result):
return super(TestCase, self).run(result)
def setUp(self):
# Restore the original temporary directory. Node ``init_tempdir``
# mangles it and many tests manage to get that method called.
self.addCleanup(
partial(setattr, tempfile, "tempdir", tempfile.tempdir),
)
return super(_TestCaseMixin, self).setUp()
class _DummyCase(_case.TestCase):
def dummy(self):
pass
_dummyCase = _DummyCase("dummy")
def mktemp(self):
return mktemp()
def assertRaises(self, *a, **kw):
return self._dummyCase.assertRaises(*a, **kw)
class SyncTestCase(_TestCaseMixin, TestCase):
"""