'A context manager which cleans up unwanted attributes on a test case
(or any other object).'

@contextlib.contextmanager
def cleanup_object(self, test):

    vanilla_attrs = set(test.__dict__)
    try:
        (yield test)
    finally:
        spurious_attrs = (set(test.__dict__) - vanilla_attrs)
        for name in spurious_attrs:
            del test.__dict__[name]
