Skip to content
Merged
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
34 changes: 18 additions & 16 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def _test():
from _colorize import ANSIColors, can_colorize


__unittest = True

class TestResults(namedtuple('TestResults', 'failed attempted')):
def __new__(cls, failed, attempted, *, skipped=0):
results = super().__new__(cls, failed, attempted)
Expand Down Expand Up @@ -390,11 +392,11 @@ def __init__(self, out):
# still use input() to get user input
self.use_rawinput = 1

def set_trace(self, frame=None):
def set_trace(self, frame=None, *, commands=None):
self.__debugger_used = True
if frame is None:
frame = sys._getframe().f_back
pdb.Pdb.set_trace(self, frame)
pdb.Pdb.set_trace(self, frame, commands=commands)

def set_continue(self):
# Calling set_continue unconditionally would break unit test
Expand Down Expand Up @@ -1230,7 +1232,7 @@ class DocTestRunner:
`OutputChecker` to the constructor.

The test runner's display output can be controlled in two ways.
First, an output function (`out) can be passed to
First, an output function (`out`) can be passed to
`TestRunner.run`; this function will be called with strings that
should be displayed. It defaults to `sys.stdout.write`. If
capturing the output is not sufficient, then the display output
Expand Down Expand Up @@ -1398,11 +1400,11 @@ def __run(self, test, compileflags, out):
exec(compile(example.source, filename, "single",
compileflags, True), test.globs)
self.debugger.set_continue() # ==== Example Finished ====
exception = None
exc_info = None
except KeyboardInterrupt:
raise
except:
exception = sys.exc_info()
except BaseException as exc:
exc_info = type(exc), exc, exc.__traceback__.tb_next
self.debugger.set_continue() # ==== Example Finished ====

got = self._fakeout.getvalue() # the actual output
Expand All @@ -1411,21 +1413,21 @@ def __run(self, test, compileflags, out):

# If the example executed without raising any exceptions,
# verify its output.
if exception is None:
if exc_info is None:
if check(example.want, got, self.optionflags):
outcome = SUCCESS

# The example raised an exception: check if it was expected.
else:
formatted_ex = traceback.format_exception_only(*exception[:2])
if issubclass(exception[0], SyntaxError):
formatted_ex = traceback.format_exception_only(*exc_info[:2])
if issubclass(exc_info[0], SyntaxError):
# SyntaxError / IndentationError is special:
# we don't care about the carets / suggestions / etc
# We only care about the error message and notes.
# They start with `SyntaxError:` (or any other class name)
exception_line_prefixes = (
f"{exception[0].__qualname__}:",
f"{exception[0].__module__}.{exception[0].__qualname__}:",
f"{exc_info[0].__qualname__}:",
f"{exc_info[0].__module__}.{exc_info[0].__qualname__}:",
)
exc_msg_index = next(
index
Expand All @@ -1436,7 +1438,7 @@ def __run(self, test, compileflags, out):

exc_msg = "".join(formatted_ex)
if not quiet:
got += _exception_traceback(exception)
got += _exception_traceback(exc_info)

# If `example.exc_msg` is None, then we weren't expecting
# an exception.
Expand Down Expand Up @@ -1465,7 +1467,7 @@ def __run(self, test, compileflags, out):
elif outcome is BOOM:
if not quiet:
self.report_unexpected_exception(out, test, example,
exception)
exc_info)
failures += 1
else:
assert False, ("unknown outcome", outcome)
Expand Down Expand Up @@ -2327,7 +2329,7 @@ def runTest(self):
sys.stdout = old

if results.failed:
raise self.failureException(self.format_failure(new.getvalue()))
raise self.failureException(self.format_failure(new.getvalue().rstrip('\n')))

def format_failure(self, err):
test = self._dt_test
Expand Down Expand Up @@ -2737,7 +2739,7 @@ def testsource(module, name):
return testsrc

def debug_src(src, pm=False, globs=None):
"""Debug a single doctest docstring, in argument `src`'"""
"""Debug a single doctest docstring, in argument `src`"""
testsrc = script_from_examples(src)
debug_script(testsrc, pm, globs)

Expand Down Expand Up @@ -2873,7 +2875,7 @@ def get(self):
def _test():
import argparse

parser = argparse.ArgumentParser(description="doctest runner")
parser = argparse.ArgumentParser(description="doctest runner", color=True)
parser.add_argument('-v', '--verbose', action='store_true', default=False,
help='print very verbose output for all tests')
parser.add_argument('-o', '--option', action='append',
Expand Down
9 changes: 9 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
self.commands_bnum = None # The breakpoint number for which we are
# defining a list

def set_trace(self, frame=None, *, commands=None):
if frame is None:
frame = sys._getframe().f_back

if commands is not None:
self.rcLines.extend(commands)

super().set_trace(frame)

def sigint_handler(self, signum, frame):
if self.allow_kbdint:
raise KeyboardInterrupt
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_concurrent_futures/test_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ProcessPoolForkWaitTest(ProcessPoolForkWaitTest): # TODO: RUSTPYTHON
def test_first_completed(self): super().test_first_completed() # TODO: RUSTPYTHON
@unittest.skipIf(sys.platform == 'linux', "TODO: RUSTPYTHON Fatal Python error: Segmentation fault")
def test_first_completed_some_already_completed(self): super().test_first_completed_some_already_completed() # TODO: RUSTPYTHON
@unittest.skipIf(sys.platform == 'linux', "TODO: RUSTPYTHON flaky")
@unittest.skipIf(sys.platform != 'win32', "TODO: RUSTPYTHON flaky")
def test_first_exception(self): super().test_first_exception() # TODO: RUSTPYTHON
@unittest.skipIf(sys.platform == 'linux', "TODO: RUSTPYTHON flaky")
def test_first_exception_one_already_failed(self): super().test_first_exception_one_already_failed() # TODO: RUSTPYTHON
Expand Down
12 changes: 8 additions & 4 deletions Lib/test/test_dbm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test script for the dbm.open function based on testdumbdbm.py"""

import sys
import unittest
import dbm
import os
Expand Down Expand Up @@ -252,10 +253,13 @@ def setUp(self):
assert mod.__name__.startswith('dbm.')
suffix = mod.__name__[4:]
testname = f'TestCase_{suffix}'
globals()[testname] = type(testname,
(AnyDBMTestCase, unittest.TestCase),
{'module': mod})

cls = type(testname,
(AnyDBMTestCase, unittest.TestCase),
{'module': mod})
# TODO: RUSTPYTHON; sqlite3 file locking prevents cleanup on Windows
if suffix == 'sqlite3' and sys.platform == 'win32':
cls = unittest.skip("TODO: RUSTPYTHON; sqlite3 file locking on Windows")(cls)
globals()[testname] = cls

if __name__ == "__main__":
unittest.main()
Loading
Loading