You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ python3.12-mpytesttest/====================================================================testsessionstarts====================================================================platformlinux--Python3.12.1, pytest-7.4.4, pluggy-1.3.0rootdir: /build/parsoconfigfile: pytest.inicollected1348itemstest/test_cache.py ......... [ 0%]
test/test_diff_parser.py .................................................................................. [ 6%]
test/test_dump_tree.py .......... [ 7%]
test/test_error_recovery.py ............. [ 8%]
test/test_file_python_errors.py ..... [ 8%]
test/test_fstring.py ..................................................................... [ 13%]
test/test_get_code.py ............. [ 14%]
test/test_grammar.py . [ 14%]
test/test_load_grammar.py ........... [ 15%]
test/test_normalizer_issues_files.py ............................. [ 17%]
test/test_old_fast_parser.py ............... [ 19%]
test/test_param_splitting.py ....... [ 19%]
test/test_parser.py ................................................................................................................................. [ 29%]
............. [ 30%]
test/test_parser_tree.py ............................................................................... [ 35%]
test/test_pep8.py ... [ 36%]
test/test_pgen2.py .................................................................................................................................. [ 45%]
............................................................................................................................................. [ 56%]
test/test_prefix.py ...................... [ 57%]
test/test_python_errors.py ...........FF............................................................................................................. [ 66%]
............................F....................F..FFF.....FFFFF.............................................................F...................... [ 78%]
..................................................................................................................................... [ 87%]
test/test_tokenize.py ............................................................................................................................... [ 97%]
. [ 97%]
test/test_utils.py ................................... [100%]
=========================================================================FAILURES==========================================================================____________________________________________________test_python_exception_matches[deff(x=3, y): pass] _____________________________________________________code='def f(x=3, y): pass'
@pytest.mark.parametrize('code', FAILING_EXAMPLES)
deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEAssertionError: assert'SyntaxError: non-default argument follows default argument'in ['SyntaxError: parameter without a default follows parameter with a default']
test/test_python_errors.py:42: AssertionError______________________________________________________test_python_exception_matches[lambdax=3, y: x] ______________________________________________________code='lambda x=3, y: x'
@pytest.mark.parametrize('code', FAILING_EXAMPLES)
deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEAssertionError: assert'SyntaxError: non-default argument follows default argument'in ['SyntaxError: parameter without a default follows parameter with a default']
test/test_python_errors.py:42: AssertionError__________________________________________________________test_python_exception_matches[f"{*x}"] ___________________________________________________________code='f"{*x}"'
@pytest.mark.parametrize('code', FAILING_EXAMPLES)
deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEassert"SyntaxError: f-string: can't use starred expression here"in ["SyntaxError: can't use starred expression here"]
test/test_python_errors.py:42: AssertionError___________________________________________________________test_python_exception_matches[f"{}"] ____________________________________________________________code='f"{}"'
@pytest.mark.parametrize('code', FAILING_EXAMPLES)
deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEassert'SyntaxError: invalid syntax'in ["SyntaxError: f-string: valid expression required before '}'"]
test/test_python_errors.py:42: AssertionError___________________________________________________________test_python_exception_matches[f"{#}"] ___________________________________________________________code='f"{#}"' @pytest.mark.parametrize('code', FAILING_EXAMPLES)deftest_python_exception_matches(code): wanted, line_nr = _get_actual_exception(code) errors = _get_error_list(code) actual = None if errors: error, = errors actual = error.message> assert actual in wantedE assert 'SyntaxError: invalid syntax' in ["SyntaxError: '{' wasneverclosed"]test/test_python_errors.py:42: AssertionError__________________________________________________________ test_python_exception_matches[f'{1!b}'] __________________________________________________________code = "f'{1!b}'" @pytest.mark.parametrize('code', FAILING_EXAMPLES) def test_python_exception_matches(code): wanted, line_nr = _get_actual_exception(code) errors = _get_error_list(code) actual = None if errors: error, = errors actual = error.message> assert actual in wantedE assert "SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'" in ["SyntaxError: f-string: invalid conversion character 'b': expected 's', 'r', or 'a'"]test/test_python_errors.py:42: AssertionError_______________________________________________________ test_python_exception_matches[f'{1:{5:{3}}}'] _______________________________________________________code = "f'{1:{5:{3}}}'" @pytest.mark.parametrize('code', FAILING_EXAMPLES) def test_python_exception_matches(code):> wanted, line_nr = _get_actual_exception(code)test/test_python_errors.py:35: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _code = "f'{1:{5:{3}}}'" def _get_actual_exception(code): with warnings.catch_warnings(): # We don't care about warnings where locals/globals misbehave here. # It's as simple as either an error or not. warnings.filterwarnings('ignore', category=SyntaxWarning) try: compile(code, '<unknown>', 'exec') except (SyntaxError, IndentationError) as e: wanted = e.__class__.__name__ + ': ' + e.msg line_nr = e.lineno except ValueError as e: # The ValueError comes from byte literals in Python 2 like '\x' # that are oddly enough not SyntaxErrors. wanted = 'SyntaxError: (value error) ' + str(e) line_nr = None else:> assert False, "The piece of code should raise an exception."E AssertionError: The piece of code should raise an exception.E assert Falsetest/test_python_errors.py:118: AssertionError_______________________________________________________ test_python_exception_matches[f'{continue}'] ________________________________________________________code = "f'{continue}'" @pytest.mark.parametrize('code', FAILING_EXAMPLES) def test_python_exception_matches(code): wanted, line_nr = _get_actual_exception(code) errors = _get_error_list(code) actual = None if errors: error, = errors actual = error.message> assert actual in wantedE assert 'SyntaxError: f-string: invalid syntax' in ["SyntaxError: f-string: expecting a valid expression after '{'"]test/test_python_errors.py:42: AssertionError__________________________________________________________ test_python_exception_matches[f'{1;1}'] __________________________________________________________code = "f'{1;1}'" @pytest.mark.parametrize('code', FAILING_EXAMPLES) def test_python_exception_matches(code): wanted, line_nr = _get_actual_exception(code) errors = _get_error_list(code) actual = None if errors: error, = errors actual = error.message> assert actual in wantedE assert 'SyntaxError: f-string: invalid syntax' in ["SyntaxError: f-string: expecting '=', or '!', or ':', or '}'"]
test/test_python_errors.py:42: AssertionError__________________________________________________________test_python_exception_matches[f'{a;}'] ___________________________________________________________code="f'{a;}'"@pytest.mark.parametrize('code', FAILING_EXAMPLES)deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEassert'SyntaxError: f-string: invalid syntax'in ["SyntaxError: f-string: expecting '=', or '!', or ':', or '}'"]
test/test_python_errors.py:42: AssertionError________________________________________________________test_python_exception_matches[f'{b""""}'] _________________________________________________________code='f\'{b"" ""}\''@pytest.mark.parametrize('code', FAILING_EXAMPLES)deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEAssertionError: assert'SyntaxError: f-string: cannot mix bytes and nonbytes literals'in ['SyntaxError: cannot mix bytes and nonbytes literals']
test/test_python_errors.py:42: AssertionError_________________________________________________________test_python_exception_matches[f"{'\\n'}"] _________________________________________________________code='f"{\'\\n\'}"'@pytest.mark.parametrize('code', FAILING_EXAMPLES)deftest_python_exception_matches(code):
>wanted, line_nr=_get_actual_exception(code)
test/test_python_errors.py:35:
_______________________________________________________________________________code='f"{\'\\n\'}"'def_get_actual_exception(code):
withwarnings.catch_warnings():
# We don't care about warnings where locals/globals misbehave here.# It's as simple as either an error or not.warnings.filterwarnings('ignore', category=SyntaxWarning)
try:
compile(code, '<unknown>', 'exec')
except (SyntaxError, IndentationError) ase:
wanted=e.__class__.__name__+': '+e.msgline_nr=e.linenoexceptValueErrorase:
# The ValueError comes from byte literals in Python 2 like '\x'# that are oddly enough not SyntaxErrors.wanted='SyntaxError: (value error) '+str(e)
line_nr=Noneelse:
>assertFalse, "The piece of code should raise an exception."EAssertionError: Thepieceofcodeshouldraiseanexception.
EassertFalsetest/test_python_errors.py:118: AssertionError_________________________________________________________test_python_exception_matches[f'{1=!b}'] __________________________________________________________code="f'{1=!b}'"@pytest.mark.parametrize('code', FAILING_EXAMPLES)deftest_python_exception_matches(code):
wanted, line_nr=_get_actual_exception(code)
errors=_get_error_list(code)
actual=Noneiferrors:
error, =errorsactual=error.message>assertactualinwantedEassert"SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'"in ["SyntaxError: f-string: invalid conversion character 'b': expected 's', 'r', or 'a'"]
test/test_python_errors.py:42: AssertionError==================================================================shorttestsummaryinfo==================================================================FAILEDtest/test_python_errors.py::test_python_exception_matches[deff(x=3, y): pass] -AssertionError: assert'SyntaxError: non-default argument follows default argument'in ['SyntaxError: parameterwithoutadefaultfollowsparameterwith...
FAILEDtest/test_python_errors.py::test_python_exception_matches[lambdax=3, y: x] -AssertionError: assert'SyntaxError: non-default argument follows default argument'in ['SyntaxError: parameterwithoutadefaultfollowsparameterwith...
FAILEDtest/test_python_errors.py::test_python_exception_matches[f"{*x}"] -assert"SyntaxError: f-string: can't use starred expression here"in ["SyntaxError: can't use starred expression here"]
FAILEDtest/test_python_errors.py::test_python_exception_matches[f"{}"] - assert 'SyntaxError: invalid syntax' in ["SyntaxError: f-string: valid expression required before '}'"]
FAILEDtest/test_python_errors.py::test_python_exception_matches[f"{#}"] - assert 'SyntaxError: invalid syntax' in ["SyntaxError: '{' was never closed"]FAILEDtest/test_python_errors.py::test_python_exception_matches[f'{1!b}'] - assert "SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'" in ["SyntaxError: f-string: invalid conversion character 'b': ex...
FAILED test/test_python_errors.py::test_python_exception_matches[f'{1:{5:{3}}}'] - AssertionError: The piece of code should raise an exception.
FAILED test/test_python_errors.py::test_python_exception_matches[f'{continue}'] - assert 'SyntaxError: f-string: invalid syntax' in ["SyntaxError: f-string: expecting a valid expression after '{'"]
FAILEDtest/test_python_errors.py::test_python_exception_matches[f'{1;1}'] -assert'SyntaxError: f-string: invalid syntax'in ["SyntaxError: f-string: expecting '=', or '!', or ':', or '}'"]
FAILEDtest/test_python_errors.py::test_python_exception_matches[f'{a;}'] -assert'SyntaxError: f-string: invalid syntax'in ["SyntaxError: f-string: expecting '=', or '!', or ':', or '}'"]
FAILEDtest/test_python_errors.py::test_python_exception_matches[f'{b""""}'] -AssertionError: assert 'SyntaxError: f-string: cannot mix bytes and nonbytes literals' in ['SyntaxError: cannot mix bytes and nonbytes literals']
FAILED test/test_python_errors.py::test_python_exception_matches[f"{'\\n'}"] - AssertionError: The piece of code should raise an exception.
FAILED test/test_python_errors.py::test_python_exception_matches[f'{1=!b}'] - assert "SyntaxError: f-string: invalid conversion character: expected 's', 'r', or 'a'" in ["SyntaxError: f-string: invalid conversion character 'b': ex...
============================================================== 13 failed, 1335 passed in 4.08s ==============================================================
Assertion error "The piece of code should raise an exception." is due to Python 3.12 allows backslash in f-strings
PEP 701: Syntactic formalization of f-strings
[PEP 701](https://peps.python.org/pep-0701/) lifts some restrictions on the usage of f-strings.
Expression components inside f-strings can now be any valid Python expression, including strings reusing the same
quote as the containing f-string, multi-line expressions, comments, backslashes, and unicode escape sequences.
Hi,
tests fail with python 3.12.1
Assertion error "The piece of code should raise an exception." is due to Python 3.12 allows backslash in f-strings
https://docs.python.org/3/whatsnew/3.12.html
Kind Regards
The text was updated successfully, but these errors were encountered: