Author: jdevlieghere
Date: Fri Mar  2 02:38:11 2018
New Revision: 326552

[testsuite] Remove workaround for categories and inline tests.

Adding categories to inline tests does not work because the attribute
is set at the function level. For methods, this means it applies to all
instances of that particular class. While this is what we want in most
cases, it's not for inline tests, where different instances correspond
to different tests.

With the workaround in place, assigning a category to one test resulted
in the category applied to *all* inline tests.

This patch removes the workaround and throws an exception with an
informative error message, to prevent this from happening in the future.


Modified: lldb/trunk/packages/Python/lldbsuite/test/
--- lldb/trunk/packages/Python/lldbsuite/test/ (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/ Fri Mar  2 02:38:11 
@@ -304,15 +304,12 @@ def add_test_categories(cat):
         if isinstance(func, type) and issubclass(func, unittest2.TestCase):
             raise Exception(
                 "@add_test_categories can only be used to decorate a test 
-        # Update or set the categories attribute. For instance methods, the
-        # attribute must be set on the actual function.
-        func_for_attr = func
-        if inspect.ismethod(func_for_attr):
-            func_for_attr = func.__func__
-        if hasattr(func_for_attr, "categories"):
-            cat.extend(func_for_attr.categories)
-        setattr(func_for_attr, "categories", cat)
+        try:
+            if hasattr(func, "categories"):
+                cat.extend(func.categories)
+            setattr(func, "categories", cat)
+        except AttributeError:
+            raise Exception('Cannot assign categories to inline tests.')
         return func

lldb-commits mailing list

Reply via email to