Merge branch '3564.eliot-log-testing-python-3' into 3566.web-tests-python-3-part-2

This commit is contained in:
Itamar Turner-Trauring 2020-12-21 13:12:19 -05:00
commit a8732a3c70
3 changed files with 15 additions and 5 deletions

0
newsfragments/3564.minor Normal file
View File

View File

@ -111,7 +111,9 @@ install_requires = [
# Eliot is contemplating dropping Python 2 support. Stick to a version we
# know works on Python 2.7.
"eliot ~= 1.7",
"eliot ~= 1.7 ; python_version < '3.0'",
# On Python 3, we want a new enough version to support custom JSON encoders.
"eliot >= 1.13.0 ; python_version > '3.0'",
# Pyrsistent 0.17.0 (which we use by way of Eliot) has dropped
# Python 2 entirely; stick to the version known to work for us.

View File

@ -31,6 +31,9 @@ from twisted.internet.defer import (
maybeDeferred,
)
from ..util.jsonbytes import BytesJSONEncoder
_NAME = Field.for_types(
u"name",
[str],
@ -61,6 +64,14 @@ def eliot_logged_test(f):
class storage(object):
pass
# On Python 3, we want to use our custom JSON encoder when validating
# messages can be encoded to JSON:
if PY3:
capture = lambda f : capture_logging(None, encoder_=BytesJSONEncoder)(f)
else:
capture = lambda f : capture_logging(None)(f)
@wraps(f)
def run_and_republish(self, *a, **kw):
# Unfortunately the only way to get at the global/default logger...
@ -85,7 +96,7 @@ def eliot_logged_test(f):
# can finish the test's action.
storage.action.finish()
@capture_logging(None)
@capture
def run(self, logger):
# Record the MemoryLogger for later message extraction.
storage.logger = logger
@ -165,9 +176,6 @@ class EliotLoggedRunTest(object):
@eliot_logged_test
def run(self, result=None):
# Workaround for https://github.com/itamarst/eliot/issues/456
if PY3:
self.case.eliot_logger._validate_message = lambda *args, **kwargs: None
return self._run_tests_with_factory(
self.case,
self.handlers,