From 373b39b19d23f5dc3f5168d115297e43c4d81f8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Tue, 26 Jan 2021 13:37:48 +0100
Subject: [PATCH] test: relax assertRaisesMsg to match longer strings
With python3.10, we get the following failure:
======================================================================
FAIL: test_literalname (css_parser_tests.test_property.PropertyTestCase)
Property.literalname
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/basetest.py", line 168, in assertRaisesMsg
callableObj(*args, **kwargs)
AttributeError: can't set attribute 'literalname'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/test_property.py", line 165, in test_literalname
self.assertRaisesMsg(AttributeError, "can't set attribute", p.__setattr__,
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/basetest.py", line 179, in assertRaisesMsg
raise self.failureException(
AssertionError: Right exception, wrong message: got 'can't set attribute 'literalname'' instead of 'can't set attribute'
======================================================================
FAIL: test_specificity (css_parser_tests.test_selector.SelectorTestCase)
Selector.specificity
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/basetest.py", line 168, in assertRaisesMsg
callableObj(*args, **kwargs)
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/test_selector.py", line 414, in _set
def _set(): selector.specificity = 1
AttributeError: can't set attribute 'specificity'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/test_selector.py", line 415, in test_specificity
self.assertRaisesMsg(AttributeError, "can't set attribute", _set)
File "/builddir/build/BUILD/css-parser-1.0.6/css_parser_tests/basetest.py", line 179, in assertRaisesMsg
raise self.failureException(
AssertionError: Right exception, wrong message: got 'can't set attribute 'specificity'' instead of 'can't set attribute'
----------------------------------------------------------------------
By checking if the argument matches just a substring, we can match
those cases without making the code more complicated. Matching just
for substrings in exception messages is pretty common.
---
css_parser_tests/basetest.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/css_parser_tests/basetest.py b/css_parser_tests/basetest.py
index 2b269064a1..07e8db1136 100644
--- a/css_parser_tests/basetest.py
+++ b/css_parser_tests/basetest.py
@@ -171,7 +171,7 @@ class BaseTestCase(unittest.TestCase):
if not msg:
# No message provided: any message is fine.
return
- elif excMsg == msg:
+ elif msg in excMsg:
# Message provided, and we got the right message: passes.
return
else: