summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChris Jerdonek <chris.jerdonek@gmail.com>2018-06-27 08:46:07 -0700
committerTim Graham <timograham@gmail.com>2018-06-27 11:46:07 -0400
commitf434f5b84f7fcea9a76a551621ecce70786e2899 (patch)
tree9c6ccbfc60b172dc758434aaa61ccec802cc7690 /tests
parentf52b026168292803693cecbca061630227df1b29 (diff)
Refs #29253 -- Fixed method_decorator() crash if decorator sets a new attribute.
Regression in fdc936c9130cf4fb5d59869674b9a31cc79a7999.
Diffstat (limited to 'tests')
-rw-r--r--tests/decorators/tests.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/decorators/tests.py b/tests/decorators/tests.py
index e8f6b8d2d5..aaa09c0056 100644
--- a/tests/decorators/tests.py
+++ b/tests/decorators/tests.py
@@ -271,6 +271,21 @@ class MethodDecoratorTests(SimpleTestCase):
self.assertEqual(Test.method.__doc__, 'A method')
self.assertEqual(Test.method.__name__, 'method')
+ def test_new_attribute(self):
+ """A decorator that sets a new attribute on the method."""
+ def decorate(func):
+ func.x = 1
+ return func
+
+ class MyClass:
+ @method_decorator(decorate)
+ def method(self):
+ return True
+
+ obj = MyClass()
+ self.assertEqual(obj.method.x, 1)
+ self.assertIs(obj.method(), True)
+
def test_bad_iterable(self):
decorators = {myattr_dec_m, myattr2_dec_m}
msg = "'set' object is not subscriptable"