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

Python 3.11 traceback format changed, tests fail #1526

Closed
hroncok opened this issue Nov 4, 2021 · 1 comment · Fixed by #1527
Closed

Python 3.11 traceback format changed, tests fail #1526

hroncok opened this issue Nov 4, 2021 · 1 comment · Fixed by #1527

Comments

@hroncok
Copy link
Contributor

hroncok commented Nov 4, 2021

When running jinja's tests with Python 3.11.0a1, two tests fail because the exception format has changed.

To reproduce, run tox:

$ tox -e py311

Alternativelly, you can limit the number of tests:

$ tox -e py311 -- tests/test_debug.py

Expected behavior: tests pass.

Actual behavior:

GLOB sdist-make: .../jinja/setup.py
py311 inst-nodeps: .../jinja/.tox/.tmp/package/1/Jinja2-3.1.0.dev0.zip
py311 installed: attrs==21.2.0,iniconfig==1.1.1,Jinja2 @ file://.../jinja/.tox/.tmp/package/1/Jinja2-3.1.0.dev0.zip,MarkupSafe==2.0.1,packaging==21.2,pluggy==1.0.0,py @ https://github.com/pytest-dev/py/archive/refs/heads/master.zip,pyparsing==2.4.7,pytest==6.2.5,toml==0.10.2
py311 run-test-pre: PYTHONHASHSEED='705390215'
py311 run-test: commands[0] | pytest -v --tb=short --basetemp=.../jinja/.tox/py311/tmp tests/test_debug.py
============================= test session starts ==============================
platform linux -- Python 3.11.0a1, pytest-6.2.5, py-1.10.1, pluggy-1.0.0 -- .../jinja/.tox/py311/bin/python
cachedir: .tox/py311/.pytest_cache
rootdir: .../jinja, configfile: setup.cfg
collecting ... collected 7 items

tests/test_debug.py::TestDebug::test_runtime_error FAILED                [ 14%]
tests/test_debug.py::TestDebug::test_syntax_error PASSED                 [ 28%]
tests/test_debug.py::TestDebug::test_regular_syntax_error FAILED         [ 42%]
tests/test_debug.py::TestDebug::test_pickleable_syntax_error PASSED      [ 57%]
tests/test_debug.py::TestDebug::test_include_syntax_error_source PASSED  [ 71%]
tests/test_debug.py::TestDebug::test_local_extraction PASSED             [ 85%]
tests/test_debug.py::TestDebug::test_get_corresponding_lineno_traceback PASSED [100%]

=================================== FAILURES ===================================
_________________________ TestDebug.test_runtime_error _________________________
tests/test_debug.py:35: in test_runtime_error
    self.assert_traceback_matches(
tests/test_debug.py:26: in assert_traceback_matches
    assert (
E   AssertionError: Traceback did not match:
E     
E     Traceback (most recent call last):
E       File ".../jinja/tests/test_debug.py", line 22, in assert_traceback_matches
E         callback()
E         ^^^^^^^^^^
E       File ".../jinja/tests/test_debug.py", line 32, in test
E         tmpl.render(fail=lambda: 1 / 0)
E         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       File ".../jinja/.tox/py311/lib/python3.11/site-packages/jinja2/environment.py", line 1304, in render
E         self.environment.handle_exception()
E         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       File ".../jinja/.tox/py311/lib/python3.11/site-packages/jinja2/environment.py", line 925, in handle_exception
E         raise rewrite_traceback_stack(source=source)
E         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       File ".../jinja/tests/res/templates/broken.html", line 2, in <module>
E         {{ fail() }}
E         ^^^^^^^^^^^^
E       File ".../jinja/tests/test_debug.py", line 32, in <lambda>
E         tmpl.render(fail=lambda: 1 / 0)
E                                  ~~^~~
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
_____________________ TestDebug.test_regular_syntax_error ______________________
tests/test_debug.py:65: in test_regular_syntax_error
    self.assert_traceback_matches(
tests/test_debug.py:26: in assert_traceback_matches
    assert (
E   AssertionError: Traceback did not match:
E     
E     Traceback (most recent call last):
E       File ".../jinja/tests/test_debug.py", line 22, in assert_traceback_matches
E         callback()
E         ^^^^^^^^^^
E       File ".../jinja/tests/test_debug.py", line 63, in test
E         raise TemplateSyntaxError("wtf", 42)
E         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E     jinja2.exceptions.TemplateSyntaxError: wtf
E       line 42
E     
E     expected:
E     
E       File ".*debug.pyc?", line \d+, in test
E         raise TemplateSyntaxError\("wtf", 42\)
E     (jinja2\.exceptions\.)?TemplateSyntaxError: wtf
E       line 42
E   assert None is not None
=========================== short test summary info ============================
FAILED tests/test_debug.py::TestDebug::test_runtime_error - AssertionError: T...
FAILED tests/test_debug.py::TestDebug::test_regular_syntax_error - AssertionE...
========================= 2 failed, 5 passed in 0.03s ==========================
ERROR: InvocationError for command .../jinja/.tox/py311/bin/pytest -v --tb=short --basetemp=.../jinja/.tox/py311/tmp tests/test_debug.py (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py311: commands failed

Environment:

I will look at a possible fixer.

@davidism davidism changed the title Python 3.11: Traceback format has chnaged, tests/test_debug.py::TestDebug::test_(regular_syntax|runtime)_error fails Python 3.11 traceback format changed, tests fail Nov 4, 2021
hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
@hroncok
Copy link
Contributor Author

hroncok commented Nov 4, 2021

Fix ready in #1527

hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
hroncok added a commit to hroncok/jinja that referenced this issue Nov 4, 2021
Fixes pallets#1526

Before:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
    ZeroDivisionError: division by zero

After:

      File ".../broken.html", line 2, in <module>
        {{ fail() }}
        ^^^^^^^^^^^^
      File ".../test_debug.py", line 32, in <lambda>
        tmpl.render(fail=lambda: 1 / 0)
                                 ~~^~~
    ZeroDivisionError: division by zero
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 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.

1 participant