Skip to content

Commit

Permalink
✨ add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MeditationDuck committed Sep 11, 2024
1 parent 027a408 commit b865aa0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions wake/testing/pytest_plugin_multiprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def _exception_handler(
try:
if attach:
sys.stdin = os.fdopen(0)
console.print(f"Used random seed '{self._random_seed.hex()}'")
attach_debugger(e_type, e, tb)
finally:
self._setup_stdio()
Expand Down
23 changes: 19 additions & 4 deletions wake/testing/pytest_plugin_single.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Iterable, List, Optional
from typing import Iterable, List, Optional, Type

from pytest import Session

from types import TracebackType

from wake.cli.console import console
from wake.config import WakeConfig
from wake.development.globals import (
Expand All @@ -25,6 +27,7 @@ class PytestWakePluginSingle:
_cov_proc_count: Optional[int]
_random_seeds: List[bytes]
_debug: bool
_exception_handled: bool

def __init__(
self,
Expand All @@ -40,10 +43,22 @@ def __init__(

def pytest_runtest_setup(self, item):
reset_exception_handled()
self._exception_handled = False

def pytest_exception_interact(self, node, call, report):
if self._debug:
attach_debugger(call.excinfo.type, call.excinfo.value, call.excinfo.tb)
if self._debug and not self._exception_handled:
self._exception_handler(call.excinfo.type, call.excinfo.value, call.excinfo.tb)


def _exception_handler(
self,
e_type: Optional[Type[BaseException]],
e: Optional[BaseException],
tb: Optional[TracebackType],
) -> None:
self._exception_handled = True
console.print(f"Used random seed '{self._random_seeds[0].hex()}'")
attach_debugger(e_type, e, tb)

def pytest_runtestloop(self, session: Session):
if (
Expand All @@ -64,7 +79,7 @@ def pytest_runtestloop(self, session: Session):
console.print(f"Using random seed '{self._random_seeds[0].hex()}'")

if self._debug:
set_exception_handler(attach_debugger)
set_exception_handler(self._exception_handler)
if coverage:
set_coverage_handler(CoverageHandler(self._config))

Expand Down

0 comments on commit b865aa0

Please sign in to comment.