import unittest
import inspect


def AbstractTestCase(name, cls):
    """Support tests for abstract base classes.

    To be used as base class when defining test cases for abstract
    class implementations. cls will be bound to the attribute `name`
    in the returned base class. This allows tests in the subclass to
    access the abstract base class or its concretization.
    """
    class BaseTestCase(unittest.TestCase):
        """TestCase that is skipped if the tested class is abstract."""
        def run(self, *args, **opts):
            """Run the test case only for non-abstract test classes."""
            if inspect.isabstract(getattr(self, name)):
                return
            else:
                return super(BaseTestCase, self).run(*args, **opts)
    setattr(BaseTestCase, name, cls)
    return BaseTestCase