Allow per-call `start_method`/`loglevel` overrides

In `tests/devx/conftest.py::spawn`, refactor the
fixture-internal closures so consumer tests can pass
explicit `start_method`/`loglevel` to each `_spawn()`
invocation rather than only inheriting the fixture-
scoped parametrize values.

Deats,
- promote `set_spawn_method()` and `set_loglevel()`
  to take their respective values as fn params (vs
  closing over the fixture-scope vars).
- give `_spawn()` `start_method=start_method` and
  `loglevel: str|None = None` kwargs so callers
  override one-off without re-parametrizing the
  suite. NOTE: this drops the implicit fixture-
  scoped `loglevel` forward — `_spawn()` callers
  now must pass `loglevel=...` explicitly.
- TODO: figure out how `--ll <level>` should map to
  the default (currently `None` → uses env-var or
  tractor default).
- add a docstring to `_spawn()` so its role as the
  consumer-facing closure is obvious from `help()`.

Also,
- `assert_before()` now returns the `.before` output
  on success (was `None`); add a one-line docstring
  describing the new return contract.

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
subint_forkserver_backend
Gud Boi 2026-04-30 14:17:41 -04:00
parent 8bc304f094
commit 486249d74f
1 changed files with 25 additions and 6 deletions

View File

@ -96,7 +96,9 @@ def spawn(
# disable all ANSI color output
# os.environ['NO_COLOR'] = '1'
def set_spawn_method():
def set_spawn_method(
start_method: str,
):
'''
Drive the actor-spawn backend inside the spawned
`examples/debugging/<script>.py` subproc via env-var
@ -106,7 +108,9 @@ def spawn(
'''
os.environ['TRACTOR_SPAWN_METHOD'] = start_method
def set_loglevel():
def set_loglevel(
loglevel: str|None,
):
'''
Forward the test-suite parametrized `loglevel` into the
spawned `examples/debugging/<script>.py` subproc via
@ -125,12 +129,24 @@ def spawn(
def _spawn(
cmd: str,
expect_timeout: float = 4,
start_method: str = start_method,
loglevel: str|None = None,
**mkcmd_kwargs,
) -> pty_spawn.spawn:
'''
Inner closure handed to consumer tests to invoke
`pytest.Pytester.spawn`
'''
nonlocal spawned
unset_colors()
set_spawn_method()
set_loglevel()
set_spawn_method(start_method=start_method)
set_loglevel(
loglevel=loglevel,
# ?TODO^ when should this be set by `--ll <level>` ?
# by default we apply 'error' but there should be a diff
# vs. when the flag IS NOT passed?
)
spawned = testdir.spawn(
cmd=mk_cmd(
cmd,
@ -322,10 +338,13 @@ def in_prompt_msg(
def assert_before(
child: SpawnBase,
patts: list[str],
**kwargs,
) -> str:
'''
Assert a patter is in `child.before.decode() -> str`,
return the full `.before` output on success.
) -> None:
'''
__tracebackhide__: bool = False
assert in_prompt_msg(