From 0a75c8e57b4b87ee533f3b08612590704b6743bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Thu, 22 Apr 2021 19:13:44 +0200 Subject: [PATCH] Add a regression test for a more defensive code.FormattedExcinfo.get_source --- testing/code/test_excinfo.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index e6a9cbaf7..287733dac 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -1397,6 +1397,29 @@ def test_cwd_deleted(pytester: Pytester) -> None: result.stderr.no_fnmatch_line("*INTERNALERROR*") +def test_regression_nagative_line_index(pytester: Pytester) -> None: + """ + With Python 3.10 alphas, there was an INTERNALERROR reported in + https://github.com/pytest-dev/pytest/pull/8227 + This test ensures it does not regress. + """ + pytester.makepyfile( + """ + import ast + import pytest + + + def test_literal_eval(): + with pytest.raises(ValueError, match="^$"): + ast.literal_eval("pytest") + """ + ) + result = pytester.runpytest() + result.stdout.fnmatch_lines(["* 1 failed in *"]) + result.stdout.no_fnmatch_line("*INTERNALERROR*") + result.stderr.no_fnmatch_line("*INTERNALERROR*") + + @pytest.mark.usefixtures("limited_recursion_depth") def test_exception_repr_extraction_error_on_recursion(): """