From: Jonas Ehrlich Date: Sun, 5 Sep 2021 19:31:15 +0000 (+0200) Subject: Add __wrapped__ attribute to _TestMethodWrapper X-Git-Tag: v6.2.0b1~23^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4427df1c81d715cbd6956b56aff3920f8655c73a;p=thirdparty%2Ftornado.git Add __wrapped__ attribute to _TestMethodWrapper Since Python 3.2 the functools.wraps decorator adds a __wrapped__ attribute pointing to the original callable, this allows wrapped functions to be introspected. --- diff --git a/tornado/test/testing_test.py b/tornado/test/testing_test.py index 37cb24602..b59ac00b2 100644 --- a/tornado/test/testing_test.py +++ b/tornado/test/testing_test.py @@ -5,6 +5,7 @@ from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, bind_unused_port, from tornado.web import Application import asyncio import contextlib +import inspect import gc import os import platform @@ -171,6 +172,14 @@ class AsyncTestCaseWrapperTest(unittest.TestCase): self.assertEqual(len(result.errors), 1) self.assertIn("Return value from test method ignored", result.errors[0][1]) + def test_unwrap(self): + class Test(AsyncTestCase): + def test_foo(self): + pass + + test = Test("test_foo") + self.assertIs(inspect.unwrap(test.test_foo), test.test_foo.orig_method) + class SetUpTearDownTest(unittest.TestCase): def test_set_up_tear_down(self): diff --git a/tornado/testing.py b/tornado/testing.py index 2e0888419..68f745dc7 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -95,6 +95,7 @@ class _TestMethodWrapper(object): def __init__(self, orig_method: Callable) -> None: self.orig_method = orig_method + self.__wrapped__ = orig_method def __call__(self, *args: Any, **kwargs: Any) -> None: result = self.orig_method(*args, **kwargs)