diff --git a/Lib/test/test_doctest3.py b/Lib/test/test_doctest3.py new file mode 100644 index 00000000000000..95ea38201b06fe --- /dev/null +++ b/Lib/test/test_doctest3.py @@ -0,0 +1,16 @@ +import unittest +import io +import contextlib +import doctest + +class TestDoctest(unittest.TestCase): + def test_syntax_error(self): + f = io.StringIO() + with contextlib.redirect_stdout(f): + doctest.run_docstring_examples('>>> 1 1', globals()) + self.assertIn(''' + 1 1 + ^^^ + SyntaxError: invalid syntax. Perhaps you forgot a comma?''', + f.getvalue()) + diff --git a/Misc/NEWS.d/next/Library/2021-09-26-09-56-46.bpo-45249.RG5p25.rst b/Misc/NEWS.d/next/Library/2021-09-26-09-56-46.bpo-45249.RG5p25.rst new file mode 100644 index 00000000000000..871de19a86d14d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-09-26-09-56-46.bpo-45249.RG5p25.rst @@ -0,0 +1,2 @@ +Added regression test for caret indicators of :exc:`SyntaxError` errors +in :mod:`doctest`.