Skip to content

Commit

Permalink
Add the options trace_threads and trace_modules to Nextline
Browse files Browse the repository at this point in the history
  • Loading branch information
TaiSakuma committed Nov 13, 2023
1 parent 3ee2c40 commit 44fa14e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions nextline/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class Nextline:
picklable.
run_no_start_from : int, optional
The first run number. The default is 1.
trace_threads : bool, optional
The default is False. If False, trace only the main thread. If True,
trace all threads.
trace_modules : bool, optional
The default is False. If False, trace only the statement. If True,
trace imported modules as well.
timeout_on_exit : float, optional
The timeout in seconds to wait for the nextline to exit from the "with"
block. The default is 3.
Expand All @@ -49,19 +55,22 @@ def __init__(
self,
statement: Statement,
run_no_start_from: int = 1,
trace_threads: bool = False,
trace_modules: bool = False,
timeout_on_exit: float = 3,
):
logger = getLogger(__name__)
logger.debug(f'statement: {reprlib.repr(statement)}')
logger.debug(f"The run number starts from {run_no_start_from}")

self._continuous = Continuous(self)

init_options = InitOptions(
statement=statement,
run_no_start_from=run_no_start_from,
trace_threads=trace_threads,
trace_modules=trace_modules,
)

logger = getLogger(__name__)
logger.debug(f'init_options: {reprlib.repr(init_options)}')

self._machine = Machine(init_options=init_options)
self._timeout_on_exit = timeout_on_exit
self._registry = self._machine.registry
Expand Down Expand Up @@ -156,12 +165,18 @@ async def reset(
self,
statement: Optional[Statement] = None,
run_no_start_from: Optional[int] = None,
trace_threads: Optional[bool] = None,
trace_modules: Optional[bool] = None,
) -> None:
"""Prepare for the next run"""
reset_options = ResetOptions(
statement=statement,
run_no_start_from=run_no_start_from,
trace_threads=trace_threads,
trace_modules=trace_modules,
)
logger = getLogger(__name__)
logger.debug(f'reset_options: {reprlib.repr(reset_options)}')
await self._machine.reset( # type: ignore
reset_options=reset_options,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/main/scenarios/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def extract_comment(line: str) -> Optional[str]:

@pytest.fixture
async def nextline(statement):
async with Nextline(statement) as y:
async with Nextline(statement, trace_threads=True, trace_modules=True) as y:
yield y


Expand Down

0 comments on commit 44fa14e

Please sign in to comment.