Skip to content

Test suite failures with Python 3.10.0a4 #1333

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

Closed
thmo opened this issue Jan 19, 2021 · 0 comments · Fixed by #1334
Closed

Test suite failures with Python 3.10.0a4 #1333

thmo opened this issue Jan 19, 2021 · 0 comments · Fixed by #1334
Milestone

Comments

@thmo
Copy link
Contributor

thmo commented Jan 19, 2021

When executed under Python 3.10, the testsuite fails with

=================================== FAILURES ===================================
_________________________ TestDebug.test_runtime_error _________________________

self = <test_debug.TestDebug object at 0x7fbdec31d4f0>
fs_env = <jinja2.environment.Environment object at 0x7fbdec31d4c0>

        def test_runtime_error(self, fs_env):
            def test():
                tmpl.render(fail=lambda: 1 / 0)
    
            tmpl = fs_env.get_template("broken.html")
>           self.assert_traceback_matches(
                test,
                r"""
      File ".*?broken.html", line 2, in (top-level template code|<module>)
        \{\{ fail\(\) \}\}
      File ".*debug?.pyc?", line \d+, in <lambda>
        tmpl\.render\(fail=lambda: 1 / 0\)
    ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
    """,
            )

tests/test_debug.py:37: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <test_debug.TestDebug object at 0x7fbdec31d4f0>
callback = <function TestDebug.test_runtime_error.<locals>.test at 0x7fbdec30b3a0>
expected_tb = '\n  File ".*?broken.html", line 2, in (top-level template code|<module>)\n    \\{\\{ fail\\(\\) \\}\\}\n  File ".*deb... <lambda>\n    tmpl\\.render\\(fail=lambda: 1 / 0\\)\nZeroDivisionError: (int(eger)? )?division (or modulo )?by zero\n'

    def assert_traceback_matches(self, callback, expected_tb):
        with pytest.raises(Exception) as exc_info:
            callback()
    
        tb = format_exception(exc_info.type, exc_info.value, exc_info.tb)
        m = re.search(expected_tb.strip(), "".join(tb))
>       assert m is not None, "Traceback did not match:\n\n%s\nexpected:\n%s" % (
            "".join(tb),
            expected_tb,
        )
E       AssertionError: Traceback did not match:
E         
E         Traceback (most recent call last):
E           File "/builddir/build/BUILD/Jinja2-2.11.2/tests/test_debug.py", line 23, in assert_traceback_matches
E             callback()
E           File "/builddir/build/BUILD/Jinja2-2.11.2/tests/test_debug.py", line 34, in test
E             tmpl.render(fail=lambda: 1 / 0)
E           File "/builddir/build/BUILD/Jinja2-2.11.2/src/jinja2/asyncsupport.py", line 71, in render
E             return original_render(self, *args, **kwargs)
E           File "/builddir/build/BUILD/Jinja2-2.11.2/src/jinja2/environment.py", line 1090, in render
E             self.environment.handle_exception()
E           File "/builddir/build/BUILD/Jinja2-2.11.2/src/jinja2/environment.py", line 832, in handle_exception
E             reraise(*rewrite_traceback_stack(source=source))
E           File "/builddir/build/BUILD/Jinja2-2.11.2/src/jinja2/_compat.py", line 28, in reraise
E             raise value.with_traceback(tb)
E           File "/builddir/build/BUILD/Jinja2-2.11.2/tests/res/templates/broken.html", line -62, in top-level template code
E           File "/builddir/build/BUILD/Jinja2-2.11.2/tests/test_debug.py", line 34, in <lambda>
E             tmpl.render(fail=lambda: 1 / 0)
E         ZeroDivisionError: division by zero
E         
E         expected:
E         
E           File ".*?broken.html", line 2, in (top-level template code|<module>)
E             \{\{ fail\(\) \}\}
E           File ".*debug?.pyc?", line \d+, in <lambda>
E             tmpl\.render\(fail=lambda: 1 / 0\)
E         ZeroDivisionError: (int(eger)? )?division (or modulo )?by zero
E         
E       assert None is not None

tests/test_debug.py:27: AssertionError

See https://bugzilla.redhat.com/show_bug.cgi?id=1907442

Environment:

  • Python version: 3.10.0a4
  • Jinja version: 2.11.2
thmo added a commit to thmo/jinja that referenced this issue Jan 19, 2021
As part of python/cpython#23113 partly
implementing PEP 626 (see https://bugs.python.org/issue42246), the
co_lnotab member of struct PyCodeObject was replaced by co_linetable,
implementing a new line number table.

This commit therefore adds linetable to the list of attributes that
are copied over into the final CodeType executed by fake_traceback()
to ensure proper line numbers and contents in fake stack traces
generated when running under Python 3.10.

Fixes pallets#1333.
@davidism davidism added this to the 3.0.0 milestone Jan 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants