@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]
A context manager which cleans up unwanted attributes on a test case
dataset/ETHPy150Open numba/llvmlite/llvmlite/tests/customize.py/_MinimalRunner.cleanup_object