]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add __wrapped__ attribute to _TestMethodWrapper 3060/head
authorJonas Ehrlich <jonas.ehrlich@gmail.com>
Sun, 5 Sep 2021 19:31:15 +0000 (21:31 +0200)
committerJonas Ehrlich <jonas.ehrlich@gmail.com>
Sun, 5 Sep 2021 19:31:15 +0000 (21:31 +0200)
Since Python 3.2 the functools.wraps decorator adds a __wrapped__ attribute
pointing to the original callable, this allows wrapped functions to be introspected.

tornado/test/testing_test.py
tornado/testing.py

index 37cb24602a28b6421926a711b277834cbee5e9ce..b59ac00b2c3d5d8fa760aee53a42dc8b0364071d 100644 (file)
@@ -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):
index 2e08884192206986a16a4aaed6a31f26960b3b2c..68f745dc7f1c5485daa5033d46fef5829096287b 100644 (file)
@@ -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)