13d179
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py
13d179
index eba9058..2c8a164 100644
13d179
--- a/Lib/test/test_pyexpat.py
13d179
+++ b/Lib/test/test_pyexpat.py
13d179
@@ -610,11 +610,9 @@ class MalformedInputText(unittest.TestCase):
13d179
     def test2(self):
13d179
         xml = "\r\n"
13d179
         parser = expat.ParserCreate()
13d179
-        try:
13d179
+        err_pattern = r'XML declaration not well-formed: line 1, column \d+'
13d179
+        with self.assertRaisesRegexp(expat.ExpatError, err_pattern):
13d179
             parser.Parse(xml, True)
13d179
-            self.fail()
13d179
-        except expat.ExpatError as e:
13d179
-            self.assertEqual(str(e), 'XML declaration not well-formed: line 1, column 14')
13d179
 
13d179
 class ForeignDTDTests(unittest.TestCase):
13d179
     """