File twisted-pr12054-testinvokationpy3.12.1.patch of Package python-Twisted
From 3038382d8b01912358419cee96a56730499881e1 Mon Sep 17 00:00:00 2001
From: Adi Roiban <adi.roiban@chevah.com>
Date: Mon, 18 Dec 2023 13:42:28 +0000
Subject: [PATCH 1/4] Run with latest Python.
---
.github/workflows/test.yaml | 6 +++---
src/twisted/newsfragments/12052.1.misc | 0
2 files changed, 3 insertions(+), 3 deletions(-)
create mode 100644 src/twisted/newsfragments/12052.1.misc
Index: twisted-23.10.0/src/twisted/trial/reporter.py
===================================================================
--- twisted-23.10.0.orig/src/twisted/trial/reporter.py
+++ twisted-23.10.0/src/twisted/trial/reporter.py
@@ -7,7 +7,7 @@
"""
Defines classes that handle the results of tests.
"""
-
+from __future__ import annotations
import os
import sys
@@ -16,7 +16,7 @@ import unittest as pyunit
import warnings
from collections import OrderedDict
from types import TracebackType
-from typing import TYPE_CHECKING, List, Tuple, Type, Union
+from typing import TYPE_CHECKING, List, Optional, Tuple, Type, Union
from zope.interface import implementer
@@ -87,6 +87,11 @@ class TestResult(pyunit.TestResult):
@ivar successes: count the number of successes achieved by the test run.
@type successes: C{int}
+
+ @ivar _startTime: The time when the current test was started. It defaults to
+ L{None}, which means that the test was skipped.
+ @ivar _lastTime: The duration of the current test run. It defaults to
+ L{None}, which means that the test was skipped.
"""
# Used when no todo provided to addExpectedFailure or addUnexpectedSuccess.
@@ -96,6 +101,9 @@ class TestResult(pyunit.TestResult):
expectedFailures: List[Tuple[itrial.ITestCase, str, "Todo"]] # type: ignore[assignment]
unexpectedSuccesses: List[Tuple[itrial.ITestCase, str]] # type: ignore[assignment]
successes: int
+ _testStarted: Optional[int]
+ # The duration of the test. It is None until the test completes.
+ _lastTime: Optional[int]
def __init__(self):
super().__init__()
@@ -104,6 +112,8 @@ class TestResult(pyunit.TestResult):
self.unexpectedSuccesses = []
self.successes = 0
self._timings = []
+ self._testStarted = None
+ self._lastTime = None
def __repr__(self) -> str:
return "<%s run=%d errors=%d failures=%d todos=%d dones=%d skips=%d>" % (
@@ -146,7 +156,8 @@ class TestResult(pyunit.TestResult):
@type test: L{pyunit.TestCase}
"""
super().stopTest(test)
- self._lastTime = self._getTime() - self._testStarted
+ if self._testStarted is not None:
+ self._lastTime = self._getTime() - self._testStarted
def addFailure(self, test, fail):
"""
Index: twisted-23.10.0/src/twisted/newsfragments/12052.removal
===================================================================
--- /dev/null
+++ twisted-23.10.0/src/twisted/newsfragments/12052.removal
@@ -0,0 +1,4 @@
+twisted.trial.reporter.TestRun.startTest() is no longer called for tests
+with skip annotation or skip attribute for Python 3.12.1 or newer.
+This is the result of upstream Python gh-106584 change.
+The behavior is not change in 3.12.0 or older.