Skip to content

Commit

Permalink
chore: Add EventStream.finish method
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jun 7, 2021
1 parent 3d5d093 commit a9fbccd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Changelog
**Added**

- GraphQL support in CLI. `#746`_
- A way to stop the Schemathesis runner's event stream manually via ``events.stop()``. `#1202`_
- A way to stop the Schemathesis runner's event stream manually via ``events.stop()`` / ``events.finish()`` methods. `#1202`_

**Changed**

Expand Down
5 changes: 5 additions & 0 deletions src/schemathesis/runner/impl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def stop(self) -> None:
"""
self.stop_event.set()

def finish(self) -> events.ExecutionEvent:
"""Stop the event stream & return the last event."""
self.stop()
return next(self)


def handle_schema_error(
error: InvalidSchema, results: TestResultSet, data_generation_method: DataGenerationMethod, recursion_level: int
Expand Down
6 changes: 6 additions & 0 deletions test/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,9 @@ def test_stop_event_stream_after_second_event(event_stream):
assert isinstance(next(event_stream), events.BeforeExecution)
event_stream.stop()
assert isinstance(next(event_stream), events.Finished)


def test_finish(event_stream):
assert isinstance(next(event_stream), events.Initialized)
event = event_stream.finish()
assert isinstance(event, events.Finished)

0 comments on commit a9fbccd

Please sign in to comment.