diff options
| author | Vinay Karanam <vinayinvicible@gmail.com> | 2021-08-23 18:28:38 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-10-20 16:48:00 +0200 |
| commit | 8806e8809e023017e6958b9fa0bbd960938e0a91 (patch) | |
| tree | 43fad5862b6ca8160f56fd9433b7c4cd9eed1683 /tests/decorators | |
| parent | 004b4620f6f4ad87261e149898940f2dcd5757ef (diff) | |
Fixed #33043 -- Made method_decorator() preserve wrapper assignments.
Regression in f434f5b84f7fcea9a76a551621ecce70786e2899.
Diffstat (limited to 'tests/decorators')
| -rw-r--r-- | tests/decorators/tests.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py index 46b01c1852..e496e2c790 100644 --- a/tests/decorators/tests.py +++ b/tests/decorators/tests.py @@ -425,6 +425,29 @@ class MethodDecoratorTests(SimpleTestCase): def __module__(cls): return "tests" + def test_wrapper_assignments(self): + """@method_decorator preserves wrapper assignments.""" + func_name = None + func_module = None + + def decorator(func): + @wraps(func) + def inner(*args, **kwargs): + nonlocal func_name, func_module + func_name = getattr(func, '__name__', None) + func_module = getattr(func, '__module__', None) + return func(*args, **kwargs) + return inner + + class Test: + @method_decorator(decorator) + def method(self): + return 'tests' + + Test().method() + self.assertEqual(func_name, 'method') + self.assertIsNotNone(func_module) + class XFrameOptionsDecoratorsTests(TestCase): """ |
