Opened 3 years ago

Closed 3 years ago

#27073 closed defect (fixed)

py3: fix artificial exception test in

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.7
Component: python3 Keywords:
Cc: chapoton Merged in:
Authors: Jeroen Demeyer Reviewers: Erik Bray
Report Upstream: N/A Work issues:
Branch: 03a5413 (Commits, GitHub, GitLab) Commit: 03a54134f0d624c53eb7db774231a9c3da4cffba
Dependencies: Stopgaps:

Status badges

Description (last modified by jdemeyer)

This test is raising an exception and then it tries to display the traceback, long after the exception has been handled by the doctest framework. In Python 3 (and also after #24986), exceptions do not stay alive forever. The solution is fixing the test to construct the traceback in an except Exception block.

sage -t src/sage_setup/docbuild/
File "src/sage_setup/docbuild/", line 212, in sage_setup.docbuild.sphinxbuild.SageSphinxLogger._log_line
Failed example:
    for line in traceback.format_exc().split('\n'):
    [#25160   ] Traceback (most recent call last):
    [#25160   ]   File ...
    [#25160   ]     self.compile_and_execute(example, compiler, test.globs)
    [#25160   ]   File ...
    [#25160   ]     exec(compiled, globs)
    [#25160   ]   File ...
    [#25160   ]     raise Exception("artificial exception")
    [#25160   ] Exception: artificial exception
    [#25160   ] NoneType: None

While I was at it, I fixed one more trivial doctest failure. All tests in src/sage_setup/docbuild now pass on Python 3.

Change History (10)

comment:1 Changed 3 years ago by jdemeyer

  • Description modified (diff)

comment:2 follow-up: Changed 3 years ago by embray

That makes sense--I agree the test is not good in the first place. Though I don't exactly understand why this changed. Just because of the sys.exc_clear()?

It makes sense though--the Python 2 behavior of keeping exception objects and tracebacks around long past their applicability was not great to begin with.

comment:3 in reply to: ↑ 2 Changed 3 years ago by jdemeyer

Replying to embray:

Just because of the sys.exc_clear()?

Indeed. Python 3 effectively does sys.exc_clear() when leaving the try/except block.

comment:4 Changed 3 years ago by jdemeyer

  • Branch set to u/jdemeyer/py3__fix_artificial_exception_test_in_sphinxbuild_py

comment:5 Changed 3 years ago by git

  • Commit set to 03a54134f0d624c53eb7db774231a9c3da4cffba

Branch pushed to git repo; I updated commit sha1. New commits:

03a5413Test type(logger) for py3 compatibility

comment:6 Changed 3 years ago by jdemeyer

  • Authors set to Jeroen Demeyer
  • Description modified (diff)
  • Status changed from new to needs_review

comment:7 Changed 3 years ago by jdemeyer

  • Cc chapoton added
  • Milestone changed from sage-8.6 to sage-8.7

comment:8 Changed 3 years ago by embray

  • Status changed from needs_review to positive_review

Makes sense, thank you.

comment:9 Changed 3 years ago by embray

  • Reviewers set to Erik Bray

comment:10 Changed 3 years ago by vbraun

  • Branch changed from u/jdemeyer/py3__fix_artificial_exception_test_in_sphinxbuild_py to 03a54134f0d624c53eb7db774231a9c3da4cffba
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.