Skip to content

Commit

Permalink
feat: Add ExecutionEvent.is_terminal attribute that indicates wheth…
Browse files Browse the repository at this point in the history
…er an event is the last one in the stream
  • Loading branch information
Stranger6667 committed Jun 21, 2021
1 parent 703430c commit 36829e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog
`Unreleased`_ - TBD
-------------------

**Added**

- ``ExecutionEvent.is_terminal`` attribute that indicates whether an event is the last one in the stream.

**Fixed**

- When ``EventStream.stop`` is called, the next event always is the last one.
Expand Down
7 changes: 7 additions & 0 deletions src/schemathesis/runner/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
class ExecutionEvent:
"""Generic execution event."""

# Whether this event is expected to be the last one in the event stream
is_terminal = False

def asdict(self, **kwargs: Any) -> Dict[str, Any]:
data = attr.asdict(self, **kwargs)
# An internal tag for simpler type identification
Expand Down Expand Up @@ -146,6 +149,8 @@ class Interrupted(ExecutionEvent):
class InternalError(ExecutionEvent):
"""An error that happened inside the runner."""

is_terminal = True

message: str = attr.ib() # pragma: no mutate
exception_type: str = attr.ib() # pragma: no mutate
exception: Optional[str] = attr.ib(default=None) # pragma: no mutate
Expand Down Expand Up @@ -182,6 +187,8 @@ class Finished(ExecutionEvent):
No more events after this point.
"""

is_terminal = True

passed_count: int = attr.ib() # pragma: no mutate
failed_count: int = attr.ib() # pragma: no mutate
errored_count: int = attr.ib() # pragma: no mutate
Expand Down

0 comments on commit 36829e2

Please sign in to comment.