From 6fad51c40d23253137ed10ef5b9247c0db1bac00 Mon Sep 17 00:00:00 2001 From: Dmitry Dygalo Date: Sun, 13 Jun 2021 16:40:25 +0200 Subject: [PATCH] chore: `ExecutionEvent.asdict` adds the `event_type` field which is the event class name --- docs/changelog.rst | 4 ++++ src/schemathesis/cli/debug.py | 1 - src/schemathesis/runner/events.py | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2630ae20ad..da242c11db 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,10 @@ Changelog `Unreleased`_ - TBD ------------------- +**Changed** + +- ``ExecutionEvent.asdict`` adds the ``event_type`` field which is the event class name. + `3.9.0`_ - 2021-06-07 --------------------- diff --git a/src/schemathesis/cli/debug.py b/src/schemathesis/cli/debug.py index 74d8d5ae95..c0e456a451 100644 --- a/src/schemathesis/cli/debug.py +++ b/src/schemathesis/cli/debug.py @@ -14,7 +14,6 @@ class DebugOutputHandler(EventHandler): def handle_event(self, context: ExecutionContext, event: events.ExecutionEvent) -> None: stream = self.file_handle.open() data = event.asdict() - data["event_type"] = event.__class__.__name__ stream.write(json.dumps(data)) stream.write("\n") diff --git a/src/schemathesis/runner/events.py b/src/schemathesis/runner/events.py index 090824a435..6e98fb96ad 100644 --- a/src/schemathesis/runner/events.py +++ b/src/schemathesis/runner/events.py @@ -1,6 +1,6 @@ import threading import time -from typing import Dict, List, Optional, Union +from typing import Any, Dict, List, Optional, Union import attr from requests import exceptions @@ -16,7 +16,11 @@ class ExecutionEvent: """Generic execution event.""" - asdict = attr.asdict + def asdict(self, **kwargs: Any) -> Dict[str, Any]: + data = attr.asdict(self, **kwargs) + # An internal tag for simpler type identification + data["event_type"] = self.__class__.__name__ + return data @attr.s(slots=True) # pragma: no mutate