Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@
prompt when a test returns an incorrect answer::

sage: sage0.quit()
sage: _ = sage0.eval("import doctest, sys, os, multiprocessing, subprocess")

Check warning on line 1458 in src/sage/doctest/forker.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Warning: slow doctest:

slow doctest:: Test ran for 5.28s cpu, 5.33s wall Check ran for 0.00s cpu, 0.00s wall
sage: _ = sage0.eval("from sage.doctest.parsing import SageOutputChecker")
sage: _ = sage0.eval("import sage.doctest.forker as sdf")
sage: _ = sage0.eval("from sage.doctest.control import DocTestDefaults")
Expand Down Expand Up @@ -1618,7 +1618,7 @@

sage: from sage.interfaces.sage0 import sage0
sage: sage0.quit()
sage: _ = sage0.eval("import doctest, sys, os, multiprocessing, subprocess")

Check warning on line 1621 in src/sage/doctest/forker.py

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, all, editable)

Warning: slow doctest:

slow doctest:: Test ran for 5.13s cpu, 5.50s wall Check ran for 0.00s cpu, 0.00s wall
sage: _ = sage0.eval("from sage.doctest.parsing import SageOutputChecker")
sage: _ = sage0.eval("import sage.doctest.forker as sdf")
sage: _ = sage0.eval("from sage.doctest.control import DocTestDefaults")
Expand Down Expand Up @@ -2039,7 +2039,8 @@
w.copied_exitcode,
w.result,
w.output,
pid=w.copied_pid)
pid=w.copied_pid,
process_tree_before_kill=w.process_tree_before_kill)

pending_tests -= 1

Expand Down Expand Up @@ -2272,7 +2273,8 @@
self.messages = ""

# Has this worker been killed (because of a time out)?
self.killed = False
self.killed: bool = False
self.process_tree_before_kill: str | None = None

def run(self):
"""
Expand Down Expand Up @@ -2502,6 +2504,17 @@
sage: W.is_alive()
False
"""
try:
import subprocess
self.process_tree_before_kill = subprocess.run(["ps", "-ef", "--cols", "1000", "--forest"],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
text=True, errors="ignore").stdout
except FileNotFoundError: # ps not available? Unlikely
pass
except subprocess.CalledProcessError:
self.process_tree_before_kill = subprocess.run(["ps", "-efwww"],
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
text=True, errors="ignore").stdout

if self.rmessages is not None:
os.close(self.rmessages)
Expand Down
26 changes: 17 additions & 9 deletions src/sage/doctest/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def report_head(self, source, fail_msg=None):
cmd += f" [failed in baseline: {failed}]"
return cmd

def _log_failure(self, source, fail_msg, event, output=None):
def _log_failure(self, source, fail_msg, event, output=None, *, process_tree_before_kill=None):
r"""
Report on the result of a failed doctest run.

Expand All @@ -236,6 +236,8 @@ def _log_failure(self, source, fail_msg, event, output=None):

- ``output`` -- (optional) string

- ``process_tree_before_kill`` -- (optional) string

EXAMPLES::

sage: from sage.doctest.reporting import DocTestReporter
Expand Down Expand Up @@ -265,13 +267,9 @@ def _log_failure(self, source, fail_msg, event, output=None):
"""
log = self.controller.log
format = self.controller.options.format
stars = "*" * 70
if format == 'sage':
stars = "*" * 70
log(f" {fail_msg}\n{stars}\n")
if output:
log(f"Tests run before {event}:")
log(output)
log(stars)
elif format == 'github':
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#using-workflow-commands-to-access-toolkit-functions
command = f'::error title={fail_msg}'
Expand All @@ -292,8 +290,18 @@ def _log_failure(self, source, fail_msg, event, output=None):
log(command)
else:
raise ValueError(f'unknown format option: {format}')

def report(self, source, timeout, return_code, results, output, pid=None):
# we log the tests ran even in github mode. The last test information is redundant since it's included
# in the {lineno} above, but the printed outputs of previously ran tests are not
if output:
log(f"Tests run before {event}:")
log(output)
log(stars)
if process_tree_before_kill:
log("Process tree before kill:")
log(process_tree_before_kill)
log(stars)

def report(self, source, timeout, return_code, results, output, pid=None, *, process_tree_before_kill=None):
"""
Report on the result of running doctests on a given source.

Expand Down Expand Up @@ -507,7 +515,7 @@ def report(self, source, timeout, return_code, results, output, pid=None):
fail_msg += " (and interrupt failed)"
else:
fail_msg += " (with %s after interrupt)" % signal_name(sig)
self._log_failure(source, fail_msg, f"{process_name} timed out", output)
self._log_failure(source, fail_msg, f"{process_name} timed out", output, process_tree_before_kill=process_tree_before_kill)
postscript['lines'].append(self.report_head(source, fail_msg))
stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests}
if not baseline.get('failed', False):
Expand Down
Loading