Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
graingert opened this issue Jan 14, 2025 · 0 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Jan 14, 2025

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

@graingert graingert added the type-bug An unexpected behavior, bug, or error label Jan 14, 2025
graingert added a commit to graingert/cpython that referenced this issue Jan 14, 2025
@picnixz picnixz added the tests Tests in the Lib/test dir label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants