Skip to content

Commit

Permalink
[#12052] Update distributed trial for the changed skip behaviour in 3…
Browse files Browse the repository at this point in the history
….12.1 (#12054)
  • Loading branch information
glyph committed Dec 20, 2023
2 parents b2a7a7b + 10e759a commit c0c6440
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
# The Python version on which the job is executed.
# We need at least one value here, so we go with latest Python version
# that we support..
python-version: ['3.12.0']
python-version: ['3.12']
# Just use the default OS.
runs-on: ['']
# Human readable short description for this job.
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
tox-env: 'macos-withcov-alldeps'

# Newest macOS and newest Python supported versions.
- python-version: '3.12.0'
- python-version: '3.12'
runs-on: 'macos-12'
job-name: 'macos-12-default-tests'
tox-env: 'macos-withcov-alldeps'
Expand All @@ -157,7 +157,7 @@ jobs:
trial-args: '--reactor=select'

# Windows, newest Python supported version with iocp reactor.
- python-version: '3.12.0'
- python-version: '3.12'
runs-on: 'windows-2022'
tox-env: 'alldeps-withcov-windows'
job-name: 'win-default-tests-iocp'
Expand Down
4 changes: 4 additions & 0 deletions src/twisted/newsfragments/12052.removal
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 14 additions & 3 deletions src/twisted/trial/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
Defines classes that handle the results of tests.
"""

from __future__ import annotations

import os
import sys
Expand All @@ -16,7 +16,7 @@
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

Expand Down Expand Up @@ -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.
Expand All @@ -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__()
Expand All @@ -104,6 +112,8 @@ def __init__(self):
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>" % (
Expand Down Expand Up @@ -146,7 +156,8 @@ def stopTest(self, test):
@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):
"""
Expand Down

0 comments on commit c0c6440

Please sign in to comment.