diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-10-21 07:09:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-21 07:09:39 (GMT) |
commit | d31e7730cd5d74efbd7320751dacd51d09cc415d (patch) | |
tree | 2ec0ee3852041197d9dda25b4e9eb6a4f5c2c9ca /Lib/test/test_grammar.py | |
parent | 2f73ed69130cdf63b773275f430c9abdab0757ad (diff) | |
download | cpython-d31e7730cd5d74efbd7320751dacd51d09cc415d.zip cpython-d31e7730cd5d74efbd7320751dacd51d09cc415d.tar.gz cpython-d31e7730cd5d74efbd7320751dacd51d09cc415d.tar.bz2 |
bpo-35029: Replace the SyntaxWarning exception with a SyntaxError. (GH-9999)
If SyntaxWarning was raised as an exception, it will be replaced
with a SyntaxError for better error reporting.
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r-- | Lib/test/test_grammar.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 9dd42b4..3d8b151 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -5,6 +5,7 @@ from test.support import check_syntax_error import inspect import unittest import sys +import warnings # testing import * from sys import * @@ -1099,6 +1100,14 @@ class GrammarTests(unittest.TestCase): else: self.fail("AssertionError not raised by 'assert False'") + with self.assertWarnsRegex(SyntaxWarning, 'assertion is always true'): + compile('assert(x, "msg")', '<testcase>', 'exec') + with warnings.catch_warnings(): + warnings.filterwarnings('error', category=SyntaxWarning) + with self.assertRaisesRegex(SyntaxError, 'assertion is always true'): + compile('assert(x, "msg")', '<testcase>', 'exec') + compile('assert x, "msg"', '<testcase>', 'exec') + ### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef # Tested below |