[issue36593] Trace function interferes with MagicMock isinstance?
Ned Batchelder
report at bugs.python.org
Wed Apr 10 20:04:16 EDT 2019
New submission from Ned Batchelder <ned at nedbatchelder.com>:
In Python 3.7.3, having a trace function in effect while mock is imported causes isinstance to be wrong for MagicMocks. I know, this sounds unlikely...
$ cat traced_sscce.py
# sscce.py
import sys
def trace(frame, event, arg):
return trace
if len(sys.argv) > 1:
sys.settrace(trace)
from unittest.mock import MagicMock
class A:
pass
m = MagicMock(spec=A)
print("isinstance: ", isinstance(m, A))
$ python3.7.2 traced_sscce.py
isinstance: True
$ python3.7.2 traced_sscce.py 1
isinstance: True
$ python3.7.2 -VV
Python 3.7.2 (default, Feb 17 2019, 16:54:12)
[Clang 10.0.0 (clang-1000.10.44.4)]
$ python3.7.3 traced_sscce.py
isinstance: True
$ python3.7.3 traced_sscce.py 1
isinstance: False
$ python3.7.3 -VV
Python 3.7.3 (default, Apr 10 2019, 10:27:53)
[Clang 10.0.0 (clang-1000.10.44.4)]
Note that if you move the mock import to before the settrace call, everything works fine.
----------
components: Library (Lib)
files: traced_sscce.py
messages: 339903
nosy: nedbat
priority: normal
severity: normal
status: open
title: Trace function interferes with MagicMock isinstance?
versions: Python 3.7
Added file: https://bugs.python.org/file48260/traced_sscce.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36593>
_______________________________________
More information about the Python-bugs-list
mailing list