[Python-checkins] bpo-38870: Use subTest in test_unparse for better error reporting (GH-20141)

Pablo Galindo webhook-mailer at python.org
Sat May 16 22:54:01 EDT 2020


https://github.com/python/cpython/commit/6341fc7257d89d798675ad6e425f7eb0b6f2b4bb
commit: 6341fc7257d89d798675ad6e425f7eb0b6f2b4bb
branch: master
author: Pablo Galindo <Pablogsal at gmail.com>
committer: GitHub <noreply at github.com>
date: 2020-05-17T03:53:57+01:00
summary:

bpo-38870: Use subTest in test_unparse for better error reporting (GH-20141)

files:
M Lib/test/test_unparse.py

diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index d543ca2526ece..67dcb1dae79ff 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -120,13 +120,15 @@ def assertASTEqual(self, ast1, ast2):
         self.assertEqual(ast.dump(ast1), ast.dump(ast2))
 
     def check_ast_roundtrip(self, code1, **kwargs):
-        ast1 = ast.parse(code1, **kwargs)
-        code2 = ast.unparse(ast1)
-        ast2 = ast.parse(code2, **kwargs)
-        self.assertASTEqual(ast1, ast2)
+        with self.subTest(code1=code1, ast_parse_kwargs=kwargs):
+            ast1 = ast.parse(code1, **kwargs)
+            code2 = ast.unparse(ast1)
+            ast2 = ast.parse(code2, **kwargs)
+            self.assertASTEqual(ast1, ast2)
 
     def check_invalid(self, node, raises=ValueError):
-        self.assertRaises(raises, ast.unparse, node)
+        with self.subTest(node=node):
+            self.assertRaises(raises, ast.unparse, node)
 
     def get_source(self, code1, code2=None):
         code2 = code2 or code1
@@ -135,11 +137,13 @@ def get_source(self, code1, code2=None):
 
     def check_src_roundtrip(self, code1, code2=None):
         code1, code2 = self.get_source(code1, code2)
-        self.assertEqual(code2, code1)
+        with self.subTest(code1=code1, code2=code2):
+            self.assertEqual(code2, code1)
 
     def check_src_dont_roundtrip(self, code1, code2=None):
         code1, code2 = self.get_source(code1, code2)
-        self.assertNotEqual(code2, code1)
+        with self.subTest(code1=code1, code2=code2):
+            self.assertNotEqual(code2, code1)
 
 class UnparseTestCase(ASTTestCase):
     # Tests for specific bugs found in earlier versions of unparse



More information about the Python-checkins mailing list