[issue41970] test_lib2to3 fails since Python 3.9

Karthikeyan Singaravelan report at bugs.python.org
Thu Oct 8 08:55:15 EDT 2020


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I guess this could be due to loading the module twice where the warning is not emitted again on reimport which test__all__ seems to do so by importing lib2to3. One obvious fix would be to pass quiet=True. Else we need to find a way to import the module fresh like using import_fresh_module. Two possible patches. I assumed running tests sequentially will provide support for isolation too.

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default True without argument,
         default False if some filters are defined)

    Without argument, it defaults to:
        check_warnings(("", Warning), quiet=True)

# Using import fresh module

diff --git a/Lib/test/test_lib2to3.py b/Lib/test/test_lib2to3.py
index 159a8387e4..861ae5ad53 100644
--- a/Lib/test/test_lib2to3.py
+++ b/Lib/test/test_lib2to3.py
@@ -1,7 +1,9 @@
 import unittest
+from test.support.import_helper import import_fresh_module
 from test.support.warnings_helper import check_warnings
 
 with check_warnings(("", PendingDeprecationWarning)):
+    lib2to3 = import_fresh_module("lib2to3")
     from lib2to3.tests import load_tests
 
 if __name__ == '__main__':

# Passing quiet=True

diff --git a/Lib/test/test_lib2to3.py b/Lib/test/test_lib2to3.py
index 159a8387e4..e4c5cade8b 100644
--- a/Lib/test/test_lib2to3.py
+++ b/Lib/test/test_lib2to3.py
@@ -1,7 +1,7 @@
 import unittest
 from test.support.warnings_helper import check_warnings
 
-with check_warnings(("", PendingDeprecationWarning)):
+with check_warnings(("", PendingDeprecationWarning), quiet=True):
     from lib2to3.tests import load_tests
 
 if __name__ == '__main__':

➜  cpython git:(master) ✗ ./python -m test test_lib2to3 test_lib2to3     
0:00:00 load avg: 0.01 Run tests sequentially
0:00:00 load avg: 0.01 [1/2] test_lib2to3
0:00:13 load avg: 0.23 [2/2] test_lib2to3

== Tests result: SUCCESS ==

All 2 tests OK.

Total duration: 27.3 sec
Tests result: SUCCESS

----------
versions: +Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41970>
_______________________________________


More information about the Python-bugs-list mailing list