def validateLogging(assertion, *assertionArgs, **assertionKwargs):
    def decorator(function):
        @wraps(function)
        def wrapper(self, *args, **kwargs):
            skipped = False

            kwargs["logger"] = logger = MemoryLogger()
            self.addCleanup(logger.validate)
            def checkForUnflushed():
                if not skipped and logger.tracebackMessages:
                    raise UnflushedTracebacks(logger.tracebackMessages)
            self.addCleanup(checkForUnflushed)
            # TestCase runs cleanups in reverse order, and we want this to
            # run *before* tracebacks are checked:
            if assertion is not None:
                self.addCleanup(lambda: skipped or assertion(
                    self, logger, *assertionArgs, **assertionKwargs))
            try:
                return function(self, *args, **kwargs)
            except SkipTest:
                skipped = True
                raise

        return wrapper
    return decorator



# PEP 8 variant:
Decorator factory for L{unittest.TestCase} methods to add logging
dataset/ETHPy150Open ClusterHQ/eliot/eliot/testing.py/validateLogging