def create_log(entries): logger = structuredlog.StructuredLogger("expected_test") data = BytesIO() handler = handlers.StreamHandler(data, formatters.JSONFormatter()) logger.add_handler(handler) for item in entries: action, kwargs = item getattr(logger, action)(**kwargs) logger.remove_handler(handler) data.seek(0) return data
def create_log(self, *args, **kwargs): logger = structuredlog.StructuredLogger("expected_test") data = StringIO.StringIO() handler = handlers.StreamHandler(data, formatters.JSONFormatter()) logger.add_handler(handler) log_entries = ([("suite_start", {"tests": [], "run_info": kwargs.get("run_info", {})})] + list(args) + [("suite_end", {})]) for item in log_entries: action, kwargs = item getattr(logger, action)(**kwargs) logger.remove_handler(handler) data.seek(0) return data