New submission from SylvainDe <[email protected]>:
On some Python versions, the following pieces of code have a different behavior
which is not something I'd expect:
```
DESCRIPT_REQUIRES_TYPE_RE = r"descriptor '\w+' requires a 'set' object but
received a 'int'"
...
def test_assertRaisesRegex(self):
self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE, set.add, 0)
def test_assertRaisesRegex_contextman(self):
with self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE):
set.add(0)
```
On impacted Python versions, only test_assertRaisesRegex_contextman fails while
test_assertRaisesRegex works fine.
Logs for the failure:
```
======================================================================
FAIL: test_assertRaisesRegex_contextman
(didyoumean_sugg_tests.SetAddIntRegexpTests)
----------------------------------------------------------------------
TypeError: descriptor 'add' for 'set' objects doesn't apply to 'int' object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/travis/build/.../didyoumean/didyoumean_sugg_tests.py", line 23,
in test_assertRaisesRegex_contextman
set.add(0)
AssertionError: "descriptor '\w+' requires a 'set' object but received a 'int'"
does not match "descriptor 'add' for 'set' objects doesn't apply to 'int'
object"
```
Either I am missing something or it looks like a bug to me.
If needed, more details/context can be found on the StackOverflow question I
opened:
https://stackoverflow.com/questions/54612348/different-error-message-when-unittest-assertraisesregex-is-called-as-a-context-m
.
I can provide the details directly here if it is relevant.
----------
components: Tests
messages: 335212
nosy: SylvainDe
priority: normal
severity: normal
status: open
title: Behavior for unittest.assertRaisesRegex differs depending on whether it
is used as a context manager
type: behavior
versions: Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35965>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com