Skip to content

Commit 599c8d5

Browse files
committed
Fix traceback tests
1 parent a777aca commit 599c8d5

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lazy from . import bar
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import traceback
2+
traceback.print_stack()
3+
while True: pass
4+
print("BAR_MODULE_LOADED")
5+
def f(): pass

Lib/test/test_traceback.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5611,11 +5611,11 @@ class TestLazyImportSuggestions(unittest.TestCase):
56115611

56125612
def test_attribute_error_does_not_reify_lazy_imports(self):
56135613
"""Printing an AttributeError should not trigger lazy import reification."""
5614-
# pkg.bar prints "BAR_MODULE_LOADED" when imported.
5614+
# lazypkg.bar prints "BAR_MODULE_LOADED" when imported.
56155615
# If lazy import is reified during suggestion computation, we'll see it.
56165616
code = textwrap.dedent("""
5617-
lazy import test.test_lazy_import.data.pkg.bar
5618-
test.test_lazy_import.data.pkg.nonexistent
5617+
lazy import test.test_lazy_import.data.lazypkg
5618+
test.test_lazy_import.data.lazypkg.nonexistent
56195619
""")
56205620
rc, stdout, stderr = assert_python_failure('-c', code)
56215621
self.assertNotIn(b"BAR_MODULE_LOADED", stdout)
@@ -5624,9 +5624,9 @@ def test_traceback_formatting_does_not_reify_lazy_imports(self):
56245624
"""Formatting a traceback should not trigger lazy import reification."""
56255625
code = textwrap.dedent("""
56265626
import traceback
5627-
lazy import test.test_lazy_import.data.pkg.bar
5627+
lazy import test.test_lazy_import.data.lazypkg
56285628
try:
5629-
test.test_lazy_import.data.pkg.nonexistent
5629+
test.test_lazy_import.data.lazypkg.nonexistent
56305630
except AttributeError:
56315631
traceback.format_exc()
56325632
print("OK")
@@ -5638,9 +5638,9 @@ def test_traceback_formatting_does_not_reify_lazy_imports(self):
56385638
def test_suggestion_still_works_for_non_lazy_attributes(self):
56395639
"""Suggestions should still work for non-lazy module attributes."""
56405640
code = textwrap.dedent("""
5641-
lazy import test.test_lazy_import.data.pkg.bar
5641+
lazy import test.test_lazy_import.data.lazypkg
56425642
# Typo for __name__
5643-
test.test_lazy_import.data.pkg.__nme__
5643+
test.test_lazy_import.data.lazypkg.__nme__
56445644
""")
56455645
rc, stdout, stderr = assert_python_failure('-c', code)
56465646
self.assertIn(b"__name__", stderr)

Makefile.pre.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,7 @@ TESTSUBDIRS= idlelib/idle_test \
26902690
test/test_lazy_import/data/pkg \
26912691
test/test_lazy_import/data/badsyntax \
26922692
test/test_lazy_import/data/circular_import_pkg \
2693+
test/test_lazy_import/data/lazypkg \
26932694
test/test_lazy_import/data/metasyntactic \
26942695
test/test_lazy_import/data/metasyntactic/foo \
26952696
test/test_lazy_import/data/metasyntactic/foo/ack \

0 commit comments

Comments
 (0)