Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sagemathgh-39147: Fix doctesting with Python 3.13
    
Adapt to upstream changes in doctest [1]:

- _name2ft was renamed to _stats
- it now records the number of skipped tests

[1] python/cpython@4f9b706c6f5d4422a398146bfd0
11daedaef1851
    
URL: sagemath#39147
Reported by: Antonio Rojas
Reviewer(s): Antonio Rojas, Gonzalo Tornaría, user202729
  • Loading branch information
Release Manager committed Jan 15, 2025
2 parents 9a91aec + 15b14ca commit d009d09
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ def __init__(self, *args, **kwds):
self.total_walltime_skips = 0
self.total_performed_tests = 0
self.total_walltime = 0
if sys.version_info < (3,13):
self._stats = self._name2ft

def _run(self, test, compileflags, out):
"""
Expand Down Expand Up @@ -840,7 +842,10 @@ def compiler(example):
self.optionflags = original_optionflags

# Record and return the number of failures and tries.
self._DocTestRunner__record_outcome(test, failures, tries)
if sys.version_info < (3,13):
self._DocTestRunner__record_outcome(test, failures, tries)
else:
self._DocTestRunner__record_outcome(test, failures, tries, walltime_skips)
self.total_walltime_skips += walltime_skips
self.total_performed_tests += tries
return TestResults(failures, tries)
Expand Down Expand Up @@ -941,7 +946,7 @@ def summarize(self, verbose=None):
sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults()
sage: import doctest, sys, os
sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
sage: DTR._name2ft['sage.doctest.forker'] = (1,120)
sage: DTR._stats['sage.doctest.forker'] = (1,120)
sage: results = DTR.summarize()
**********************************************************************
1 item had failures:
Expand All @@ -956,8 +961,8 @@ def summarize(self, verbose=None):
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
for x in self._stats.items():
name, (f, t, *_) = x
assert f <= t
totalt += t
totalf += f
Expand All @@ -982,10 +987,10 @@ def summarize(self, verbose=None):
print(self.DIVIDER, file=m)
print(count_noun(len(failed), "item"), "had failures:", file=m)
failed.sort()
for thing, (f, t) in failed:
for thing, (f, t, *_) in failed:
print(" %3d of %3d in %s" % (f, t, thing), file=m)
if verbose:
print(count_noun(totalt, "test") + " in " + count_noun(len(self._name2ft), "item") + ".", file=m)
print(count_noun(totalt, "test") + " in " + count_noun(len(self._stats), "item") + ".", file=m)
print("%s passed and %s failed." % (totalt - totalf, totalf), file=m)
if totalf:
print("***Test Failed***", file=m)
Expand Down

0 comments on commit d009d09

Please sign in to comment.