From 7db5a1c7ed61378c06841efc3d4da8ca98ce2eba Mon Sep 17 00:00:00 2001 From: Tom Hunze Date: Sat, 30 Aug 2025 22:37:08 +0200 Subject: [PATCH] python313Packages.i3ipc: fix build Upstream hasn't been very active in the past years. 1. pytest 8.4 introduced a breaking change where async tests fail instead of generating a warning when there is no async-aware plugin to handle them. - Changelog: https://github.com/pytest-dev/pytest/releases/tag/8.4.0 - Fixed by adding pytest-asyncio as a dependency. 2. Upstream expects a very old version of pytest-asyncio. To make the tests work with latest pytest-asyncio I added a patch which: - Correctly decorates the only async fixture `i3` with `@pytest_asyncio.fixture`. - Configures `loop_scope='class'` for all async tests and the async fixture `i3` to match the existing `scope='class'` on `i3`. --- .../python-modules/i3ipc/default.nix | 10 +++++++ .../i3ipc/fix-async-tests.patch | 28 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pkgs/development/python-modules/i3ipc/fix-async-tests.patch diff --git a/pkgs/development/python-modules/i3ipc/default.nix b/pkgs/development/python-modules/i3ipc/default.nix index febac35bc4a4..e63dc1f68c55 100644 --- a/pkgs/development/python-modules/i3ipc/default.nix +++ b/pkgs/development/python-modules/i3ipc/default.nix @@ -4,6 +4,7 @@ fetchFromGitHub, xorg, pytest, + pytest-asyncio, pytest-xvfb, i3, xlib, @@ -23,12 +24,21 @@ buildPythonPackage rec { rev = "v${version}"; sha256 = "13bzs9dcv27czpnnbgz7a037lm8h991c8gk0qzzk5mq5yak24715"; }; + + patches = [ + # Upstream expects a very old version of pytest-asyncio. This patch correctly + # decorates async fixtures using pytest-asyncio and configures `loop_scope` + # where needed. + ./fix-async-tests.patch + ]; + propagatedBuildInputs = [ xlib ]; fontsConf = makeFontsConf { fontDirectories = [ ]; }; FONTCONFIG_FILE = fontsConf; # Fontconfig error: Cannot load default config file nativeCheckInputs = [ pytest + pytest-asyncio xdpyinfo pytest-xvfb xorg.xvfb diff --git a/pkgs/development/python-modules/i3ipc/fix-async-tests.patch b/pkgs/development/python-modules/i3ipc/fix-async-tests.patch new file mode 100644 index 000000000000..41407c1d4878 --- /dev/null +++ b/pkgs/development/python-modules/i3ipc/fix-async-tests.patch @@ -0,0 +1,28 @@ +diff --git a/test/aio/ipctest.py b/test/aio/ipctest.py +index 88e4cda..3d0fd9c 100644 +--- a/test/aio/ipctest.py ++++ b/test/aio/ipctest.py +@@ -1,5 +1,6 @@ + from subprocess import Popen + import pytest ++import pytest_asyncio + + from i3ipc.aio import Connection + from i3ipc import CommandReply +@@ -19,7 +20,7 @@ class IpcTest: + def event_loop(self): + return asyncio.get_event_loop() + +- @pytest.fixture(scope='class') ++ @pytest_asyncio.fixture(scope='class', loop_scope='class') + async def i3(self): + process = Popen(['i3', '-c', 'test/i3.config']) + # wait for i3 to start up +diff --git a/pytest.ini b/pytest.ini +index 1ea6b80..788bdac 100644 +--- a/pytest.ini ++++ b/pytest.ini +@@ -1,2 +1,3 @@ + [pytest] + timeout = 5 ++asyncio_default_test_loop_scope = class