Type alias our `pexpect.spawn()` closure fixture
Such that we can more easily annotate any consumer test's of our `.tests.devx.conftest.spawn()` fixture which delivers a closure which, when called in a test fn body, transitively sub-invokes: `pytest.Pytester.spawn()` -> `pexpect.spawn()` IMO Expecting `Callable[[str], pexpect.pty_spawn.spawn]]` to be used all over is a bit too.. verbose?
parent
87049b991f
commit
6fd08c6e32
|
@ -5,6 +5,7 @@
|
||||||
import time
|
import time
|
||||||
from typing import (
|
from typing import (
|
||||||
Callable,
|
Callable,
|
||||||
|
TYPE_CHECKING,
|
||||||
)
|
)
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -26,14 +27,22 @@ from ..conftest import (
|
||||||
_ci_env,
|
_ci_env,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from pexpect import pty_spawn
|
||||||
|
|
||||||
|
|
||||||
|
# a fn that sub-instantiates a `pexpect.spawn()`
|
||||||
|
# and returns it.
|
||||||
|
type PexpectSpawner = Callable[[str], pty_spawn.spawn]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def spawn(
|
def spawn(
|
||||||
start_method,
|
start_method: str,
|
||||||
testdir: pytest.Pytester,
|
testdir: pytest.Pytester,
|
||||||
reg_addr: tuple[str, int],
|
reg_addr: tuple[str, int],
|
||||||
|
|
||||||
) -> Callable[[str], None]:
|
) -> PexpectSpawner:
|
||||||
'''
|
'''
|
||||||
Use the `pexpect` module shipped via `testdir.spawn()` to
|
Use the `pexpect` module shipped via `testdir.spawn()` to
|
||||||
run an `./examples/..` script by name.
|
run an `./examples/..` script by name.
|
||||||
|
@ -59,7 +68,7 @@ def spawn(
|
||||||
def _spawn(
|
def _spawn(
|
||||||
cmd: str,
|
cmd: str,
|
||||||
**mkcmd_kwargs,
|
**mkcmd_kwargs,
|
||||||
):
|
) -> pty_spawn.spawn:
|
||||||
unset_colors()
|
unset_colors()
|
||||||
return testdir.spawn(
|
return testdir.spawn(
|
||||||
cmd=mk_cmd(
|
cmd=mk_cmd(
|
||||||
|
@ -73,7 +82,7 @@ def spawn(
|
||||||
)
|
)
|
||||||
|
|
||||||
# such that test-dep can pass input script name.
|
# such that test-dep can pass input script name.
|
||||||
return _spawn
|
return _spawn # the `PexpectSpawner`, type alias.
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
|
|
Loading…
Reference in New Issue