Message335857
Context:
--------
Follow-up from https://bugs.python.org/issue35965 which was closed when we assumed the issue was on the coverage side.
After nedbat investigation, it seems like the issue comes from call to "sys.settrace".
Issue:
------
A test relying on "self.assertRaisesRegex" with raising code "set.add(0)" started to lead to a different error message recently on the CI jobs.
Indeed, instead of
"descriptor '\w+' requires a 'set' object but received a 'int'"
the raised exception was:
"descriptor 'add' for 'set' objects doesn't apply to 'int' object"
More surprisingly, the behavior was different:
- depending on whether "self.assertRaisesRegex" was used as a context manager
- on the Python version
- when coverage was used. Nedbat was able to pinpoint the root cause for this: the usage of "sys.settrace".
This can be hilighted using simple unit-tests:
======================================================================================================
import unittest
import sys
def trace(frame, event, arg):
return trace
DESCRIPT_REQUIRES_TYPE_RE = r"descriptor '\w+' requires a 'set' object but received a 'int'"
DO_SET_TRACE = True
class SetAddIntRegexpTests(unittest.TestCase):
def test_assertRaisesRegex(self):
if DO_SET_TRACE:
sys.settrace(trace)
self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE, set.add, 0)
def test_assertRaisesRegex_contextman(self):
if DO_SET_TRACE:
sys.settrace(trace)
with self.assertRaisesRegex(TypeError, DESCRIPT_REQUIRES_TYPE_RE):
set.add(0)
if __name__ == '__main__':
unittest.main()
======================================================================================================
Here are the results from the original bug:
On some versions, both tests pass:
Python 3.6 and before
Python 3.7.0a4+ (heads/master:4666ec5, Jan 26 2018, 04:14:24) - [GCC 4.8.4] - ('CPython', 'heads/master', '4666ec5'))
On some versions, only test_assertRaisesRegex_contextman fails which was the confusing part:
Python 3.7.1 (default, Dec 5 2018, 18:09:53) [GCC 5.4.0 20160609] - ('CPython', '', '')
Python 3.7.2+ (heads/3.7:3fcfef3, Feb 9 2019, 07:30:09) [GCC 5.4.0 20160609] - ('CPython', 'heads/3.7', '3fcfef3')
On some versions, both tests fail:
Python 3.8.0a1+ (heads/master:8a03ff2, Feb 9 2019, 07:30:26) [GCC 5.4.0 20160609] - ('CPython', 'heads/master', '8a03ff2')
First analysis:
---------------
Using some git bisect magic, I was able to pinpoint the commits leading to each behavior change.
- test_assertRaisesRegex_contextman starts to fail from: https://bugs.python.org/issue34126 https://github.com/python/cpython/commit/56868f940e0cc0b35d33c0070107ff3bed2d8766
- test_assertRaisesRegex starts to fail as well from: https://bugs.python.org/issue34125 https://github.com/python/cpython/commit/e89de7398718f6e68848b6340830aeb90b7d582c
From my point of view, it looks like we have 2 regressions. Please let me know if this needs to be split into 2 independant issues. |
|
Date |
User |
Action |
Args |
2019-02-18 18:06:04 | SylvainDe | set | recipients:
+ SylvainDe |
2019-02-18 18:06:04 | SylvainDe | set | messageid: <1550513164.21.0.815390267137.issue36026@roundup.psfhosted.org> |
2019-02-18 18:06:04 | SylvainDe | link | issue36026 messages |
2019-02-18 18:06:04 | SylvainDe | create | |
|