Skip to content

test_doctests failure when running tests with -werror on platforms without readline (win32, wasi) #128816

Closed
@graingert

Description

@graingert

Bug report

Bug description:

======================================================================
FAIL: test_lineendings (test.test_doctest.test_doctest)
Doctest: test.test_doctest.test_doctest.test_lineendings
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Lib/doctest.py", line 2327, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for test.test_doctest.test_doctest.test_lineendings
  File "/Lib/test/test_doctest/test_doctest.py", line 2901, in test_lineendings

----------------------------------------------------------------------
File "/Lib/test/test_doctest/test_doctest.py", line 2969, in test.test_doctest.test_doctest.test_lineendings
Failed example:
    with test_hook(dn):
        doctest.testfile("doctest_testfile.txt", package="doctest_testpkg", verbose=False)
Exception raised:
    Traceback (most recent call last):
      File "/Lib/doctest.py", line 1395, in __run
        exec(compile(example.source, filename, "single",
        ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     compileflags, True), test.globs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest test.test_doctest.test_doctest.test_lineendings[21]>", line 2, in <module>
        doctest.testfile("doctest_testfile.txt", package="doctest_testpkg", verbose=False)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Lib/doctest.py", line 2197, in testfile
        runner.run(test)
        ~~~~~~~~~~^^^^^^
      File "/Lib/doctest.py", line 1548, in run
        self.debugger = _OutputRedirectingPdb(save_stdout)
                        ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
      File "/Lib/doctest.py", line 388, in __init__
        pdb.Pdb.__init__(self, stdout=out, nosigint=True)
        ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Lib/pdb.py", line 331, in __init__
        import readline
      File "<frozen importlib._bootstrap>", line 1359, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1330, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 918, in _load_unlocked
    ImportWarning: TestImporter.exec_module() not found; falling back to load_module()

fix seems to be to upgrade to the non-deprecated exec_module interface:

From 6659cadb6074c5c9203c26c4baedb47924c2f6d3 Mon Sep 17 00:00:00 2001
From: Thomas Grainger <[email protected]>
Date: Tue, 14 Jan 2025 08:56:11 +0000
Subject: [PATCH] fix an import warning in test_doctest.py when importing
 readline in WASI

---
 Lib/test/test_doctest/test_doctest.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Lib/test/test_doctest/test_doctest.py b/Lib/test/test_doctest/test_doctest.py
index b1e165fe16b..9c39255c241 100644
--- a/Lib/test/test_doctest/test_doctest.py
+++ b/Lib/test/test_doctest/test_doctest.py
@@ -2869,6 +2869,12 @@ def get_data(self, path):
         with open(path, mode='rb') as f:
             return f.read()
 
+    def exec_module(self, module):
+        raise ImportError
+
+    def create_module(self, spec):
+        return None
+
 class TestHook:
 
     def __init__(self, pathdir):
-- 
2.43.0

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows, Other

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions