Skip to content

Commit

Permalink
Merge pull request #593 from nose-devs/fix-py312-builds
Browse files Browse the repository at this point in the history
Fixes for python3.12+
  • Loading branch information
sirosen authored Dec 22, 2023
2 parents 8ba765d + 316ba77 commit c8caaa7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.x"
python-version: "3.12"
- name: install build prereqs
run: pip install build
- name: test
run: |
python setup.py sdist
python -m build --sdist
version="$(cat nose2/__init__.py | grep '^__version__' | cut -d '"' -f2)"
cd dist
tar -xzf "nose2-${version}.tar.gz"
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-------------------

Expand Down
12 changes: 9 additions & 3 deletions nose2/plugins/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions nose2/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nose2/tests/functional/test_junitxml_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit c8caaa7

Please sign in to comment.