Fix tests with Python 3.13.0b1

This commit is contained in:
Miro Hrončok 2024-05-28 14:06:13 +02:00
commit 8a984c4565
2 changed files with 33 additions and 0 deletions

30
12698.patch Normal file
View file

@ -0,0 +1,30 @@
From a2b23ffd477dcd90de6f1cb1f4cb75e0229d0e16 Mon Sep 17 00:00:00 2001
From: Richard Si <sichard26@gmail.com>
Date: Sat, 11 May 2024 13:26:30 -0400
Subject: [PATCH] Also patch time.time_ns() in unit tests
The logging implementation in Python 3.13.0b1 uses time.time_ns() instead
of time.time().
---
tests/unit/test_base_command.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/tests/unit/test_base_command.py b/tests/unit/test_base_command.py
index 80c93799d94..f9fae651422 100644
--- a/tests/unit/test_base_command.py
+++ b/tests/unit/test_base_command.py
@@ -17,8 +17,12 @@
@pytest.fixture
def fixed_time() -> Iterator[None]:
- with patch("time.time", lambda: 1547704837.040001 + time.timezone):
- yield
+ # Patch time so logs contain a constant timestamp. time.time_ns is used by
+ # logging starting with Python 3.13.
+ year2019 = 1547704837.040001 + time.timezone
+ with patch("time.time", lambda: year2019):
+ with patch("time.time_ns", lambda: int(year2019 * 1e9)):
+ yield
class FakeCommand(Command):

View file

@ -82,6 +82,9 @@ Patch: nowarn-pip._internal.main.patch
# Upstream issue: https://github.com/pypa/packaging/issues/368
Patch: no-version-warning.patch
# Python 3.13 support: Also patch time.time_ns() in unit tests
Patch: https://github.com/pypa/pip/pull/12698.patch
%description
pip is a package management system used to install and manage software packages
written in Python. Many packages can be found in the Python Package Index