From be0d91111662c6f571d4e0c524e31a07be71273c Mon Sep 17 00:00:00 2001 From: Benjamin A. Beasley Date: Dec 22 2023 13:16:45 +0000 Subject: Fix test reporter output in Python 3.12.1 and later --- diff --git a/0001-Downstream-only-skip-test_skip_reason_in_message.patch b/0001-Downstream-only-skip-test_skip_reason_in_message.patch deleted file mode 100644 index 5ffec4c..0000000 --- a/0001-Downstream-only-skip-test_skip_reason_in_message.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 0d9ed292c29dbcdeb1164eb359f68dc15ce17cd9 Mon Sep 17 00:00:00 2001 -From: "Benjamin A. Beasley" -Date: Thu, 26 Oct 2023 10:52:25 -0400 -Subject: [PATCH] Downstream-only: skip test_skip_reason_in_message - -The message format has changed in Python 3.12.1 and in pre-releases of -Python 3.13. ---- - nose2/tests/functional/test_junitxml_plugin.py | 3 +++ - 1 file changed, 3 insertions(+) - -diff --git a/nose2/tests/functional/test_junitxml_plugin.py b/nose2/tests/functional/test_junitxml_plugin.py -index acd175d..3fec9c3 100644 ---- a/nose2/tests/functional/test_junitxml_plugin.py -+++ b/nose2/tests/functional/test_junitxml_plugin.py -@@ -1,4 +1,6 @@ - import os -+import sys -+import unittest - from xml.etree import ElementTree as ET - - from nose2.tests._common import FunctionalTestCase, TestCase, _method_name, support_file -@@ -154,6 +156,7 @@ class JunitXmlPluginFunctionalTest(FunctionalTestCase, TestCase): - self.assertEqual(prop.get("name"), "PROPERTY_NAME") - self.assertEqual(prop.get("value"), "PROPERTY_VALUE") - -+ @unittest.skipIf(sys.version_info >= (3, 12, 1), "Issue #588") - def test_skip_reason_in_message(self): - junit_report, proc = self.run_with_junitxml_loaded( - ("scenario", "junitxml", "skip_reason"), "--junit-xml" --- -2.43.0 - diff --git a/58cbe5ff35e2cc0633e7ff7c46d48a66d597a025.patch b/58cbe5ff35e2cc0633e7ff7c46d48a66d597a025.patch new file mode 100644 index 0000000..b90c063 --- /dev/null +++ b/58cbe5ff35e2cc0633e7ff7c46d48a66d597a025.patch @@ -0,0 +1,108 @@ +From 58cbe5ff35e2cc0633e7ff7c46d48a66d597a025 Mon Sep 17 00:00:00 2001 +From: Stephen Rosen +Date: Thu, 21 Dec 2023 20:25:22 -0600 +Subject: [PATCH] Fix verbose reporting of skipped tests + +On 3.12.1+, unittest doesn't call `startTest` for skipped tests. This +is treated as a fix to how tests are counted, which is why it appeared +in a point release. + +Because the nose2 path for test reporting uses the test result methods +as the point of connection between `unittest` and nose2 plugins, +losing the `startTest` call in this case means that the reporter +plugin doesn't emit proper output. + +The test result object now tracks whether or not a test has been +started, and the reporter will check this attribute to ensure that the +skipped test output is correct. +--- + docs/changelog.rst | 6 ++++++ + nose2/plugins/result.py | 12 +++++++++--- + nose2/result.py | 4 ++++ + nose2/tests/functional/test_junitxml_plugin.py | 2 +- + 4 files changed, 20 insertions(+), 4 deletions(-) + +diff --git a/docs/changelog.rst b/docs/changelog.rst +index 18ec30f5..5e1c46c1 100644 +--- a/docs/changelog.rst ++++ b/docs/changelog.rst +@@ -13,6 +13,12 @@ testsuites. + Unreleased + ---------- + ++* Fix the reporting of skipped tests in verbose mode on newer pythons (3.12.1+), ++ in which a skipped test is no longer treated as "started". ++ ++ ``nose2`` will not introduce a ``StartTestEvent`` in such cases -- ++ the fix is narrowly and adjustment to the test reporter. ++ + 0.14.0 (2023-10-04) + ------------------- + +diff --git a/nose2/plugins/result.py b/nose2/plugins/result.py +index fe953129..fb95ec7a 100644 +--- a/nose2/plugins/result.py ++++ b/nose2/plugins/result.py +@@ -80,6 +80,9 @@ def testOutcome(self, event): + etc) + + """ ++ if not event.result.test_started: ++ self._show_test_description(self.stream, event.test) ++ + if event.outcome == result.ERROR: + self.reportCategories["errors"].append(event) + self._reportError(event) +@@ -145,11 +148,14 @@ def _reportStartTest(self, event): + self.session.hooks.reportStartTest(evt) + if evt.handled: + return ++ self._show_test_description(evt.stream, event.test) ++ ++ def _show_test_description(self, stream, test): + if self.session.verbosity > 1: + # allow other plugins to override/spy on stream +- evt.stream.write(self._getDescription(event.test, errorList=False)) +- evt.stream.write(" ... ") +- evt.stream.flush() ++ stream.write(self._getDescription(test, errorList=False)) ++ stream.write(" ... ") ++ stream.flush() + + def _reportError(self, event): + self._report(event, "reportError", "E", "ERROR") +diff --git a/nose2/result.py b/nose2/result.py +index 48adc22a..fe19e8b1 100644 +--- a/nose2/result.py ++++ b/nose2/result.py +@@ -31,6 +31,9 @@ def __init__(self, session): + self.shouldStop = False + # XXX TestCase.subTest expects a result.failfast attribute + self.failfast = False ++ # track whether or not the test actually started ++ # (in py3.12.1+ a skipped test is not started) ++ self.test_started = False + + def startTest(self, test): + """Start a test case. +@@ -40,6 +43,7 @@ def startTest(self, test): + """ + event = events.StartTestEvent(test, self, time.time()) + self.session.hooks.startTest(event) ++ self.test_started = True + + def stopTest(self, test): + """Stop a test case. +diff --git a/nose2/tests/functional/test_junitxml_plugin.py b/nose2/tests/functional/test_junitxml_plugin.py +index acd175d8..1b289dd2 100644 +--- a/nose2/tests/functional/test_junitxml_plugin.py ++++ b/nose2/tests/functional/test_junitxml_plugin.py +@@ -161,7 +161,7 @@ def test_skip_reason_in_message(self): + + self.assertTestRunOutputMatches( + proc, +- stderr=r"test \(test_junitxml_skip_reason.Test" ++ stderr=r"test \(test_junitxml_skip_reason\.Test" + + _method_name() + + r"\) \.* skip", + ) diff --git a/python-nose2.spec b/python-nose2.spec index befef4b..700d5a9 100644 --- a/python-nose2.spec +++ b/python-nose2.spec @@ -25,18 +25,26 @@ Source1: nose2.1 # deprecated PyPI “mock” package (which is not actually needed for the tests on # modern Python versions). Patch: nose2-0.11.0-tox-no-dev-extra.patch -# Downstream-only: skip test_skip_reason_in_message on Python 3.13+ +# Fix verbose reporting of skipped tests # -# The message format has changed in Python 3.12.1 and in pre-releases of -# Python 3.13. +# On 3.12.1+, unittest doesn't call `startTest` for skipped tests. This +# is treated as a fix to how tests are counted, which is why it appeared +# in a point release. # -# This is a workaround while we wait for an upstream fix. +# Because the nose2 path for test reporting uses the test result methods +# as the point of connection between `unittest` and nose2 plugins, +# losing the `startTest` call in this case means that the reporter +# plugin doesn't emit proper output. +# +# The test result object now tracks whether or not a test has been +# started, and the reporter will check this attribute to ensure that the +# skipped test output is correct. +# +# Fixes: # # Python 3.13: test_skip_reason_in_message fails # https://github.com/nose-devs/nose2/issues/588 -# -# https://bugzilla.redhat.com/show_bug.cgi?id=2246281 -Patch: 0001-Downstream-only-skip-test_skip_reason_in_message.patch +Patch: %{forgeurl}/commit/58cbe5ff35e2cc0633e7ff7c46d48a66d597a025.patch BuildArch: noarch