From 6fd08c6e32d0db247c6f02106961227ed85f38a6 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 11 Jun 2025 19:19:56 -0400 Subject: [PATCH] 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? --- tests/devx/conftest.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/devx/conftest.py b/tests/devx/conftest.py index fafa1334..30393c92 100644 --- a/tests/devx/conftest.py +++ b/tests/devx/conftest.py @@ -5,6 +5,7 @@ import time from typing import ( Callable, + TYPE_CHECKING, ) import pytest @@ -26,14 +27,22 @@ from ..conftest import ( _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 def spawn( - start_method, + start_method: str, testdir: pytest.Pytester, reg_addr: tuple[str, int], -) -> Callable[[str], None]: +) -> PexpectSpawner: ''' Use the `pexpect` module shipped via `testdir.spawn()` to run an `./examples/..` script by name. @@ -59,7 +68,7 @@ def spawn( def _spawn( cmd: str, **mkcmd_kwargs, - ): + ) -> pty_spawn.spawn: unset_colors() return testdir.spawn( cmd=mk_cmd( @@ -73,7 +82,7 @@ def spawn( ) # such that test-dep can pass input script name. - return _spawn + return _spawn # the `PexpectSpawner`, type alias. @pytest.fixture(