From 55722833ca12ea90645f0020cda44efc2d8e5798 Mon Sep 17 00:00:00 2001 From: Andrzej Klajnert Date: Mon, 25 Mar 2024 15:45:27 +0100 Subject: [PATCH] Fix CI (#148) * Fix CI * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed mypy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixed tests on Windows < 3.8 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- pytest_subprocess/utils.py | 6 +++++- setup.cfg | 2 +- tests/test_asyncio.py | 27 ++++++++++++++------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pytest_subprocess/utils.py b/pytest_subprocess/utils.py index 65e1975..eece249 100644 --- a/pytest_subprocess/utils.py +++ b/pytest_subprocess/utils.py @@ -7,8 +7,12 @@ from typing import Optional from typing import Sequence from typing import Tuple +from typing import TYPE_CHECKING from typing import Union +if TYPE_CHECKING: + from .types import COMMAND + ARGUMENT = Union[str, "Any", os.PathLike] @@ -31,7 +35,7 @@ class Command: def __init__( self, - command: Union[Sequence[ARGUMENT], str], + command: "COMMAND", ): if isinstance(command, str): command = tuple(command.split(" ")) diff --git a/setup.cfg b/setup.cfg index c9da5a2..ca4dac3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ ignore = E231,W503 max-line-length = 89 [mypy] -python_version = 3.6 +python_version = 3.8 warn_return_any = True warn_unused_configs = True disallow_untyped_defs = True diff --git a/tests/test_asyncio.py b/tests/test_asyncio.py index ab8f80e..7d4cafd 100644 --- a/tests/test_asyncio.py +++ b/tests/test_asyncio.py @@ -11,22 +11,23 @@ PYTHON = sys.executable -@pytest.fixture(autouse=True) -def event_loop(request): +@pytest.fixture() +def event_loop_policy(request): if sys.platform.startswith("win"): if request.node.name.startswith("test_invalid_event_loop"): - loop = asyncio.SelectorEventLoop() + return asyncio.WindowsSelectorEventLoopPolicy() else: - loop = asyncio.ProactorEventLoop() - elif sys.version_info.minor < 7: - loop = asyncio.get_event_loop() - else: - try: - loop = asyncio.get_running_loop() - except RuntimeError: - loop = asyncio.new_event_loop() - yield loop - loop.close() + return asyncio.WindowsProactorEventLoopPolicy() + return asyncio.DefaultEventLoopPolicy() + + +if sys.platform.startswith("win") and sys.version_info < (3, 8): + + @pytest.fixture(autouse=True) + def event_loop(request, event_loop_policy): + loop = event_loop_policy.new_event_loop() + yield loop + loop.close() @pytest.mark.asyncio