Skip to content

Commit

Permalink
Handle errors in thread gracefully
Browse files Browse the repository at this point in the history
Without this, failing tests were actually being marked as successful
  • Loading branch information
rogeriochaves authored and willemt committed Jul 4, 2024
1 parent 8181457 commit 9367353
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pytest_asyncio_cooperative/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,17 @@ def sync_wrapper():
result = None
def run_in_thread():
nonlocal result
result = asyncio.run(new_task)
try:
result = asyncio.run(new_task)
except Exception as e:
result = e
thread = threading.Thread(target=run_in_thread)
thread.start()
thread.join()

if isinstance(result, Exception):
raise result # type: ignore

return result

item.runtest = sync_wrapper
Expand Down

0 comments on commit 9367353

Please sign in to comment.