Message339903
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. |
|
Date |
User |
Action |
Args |
2019-04-11 00:04:16 | nedbat | set | recipients:
+ nedbat |
2019-04-11 00:04:16 | nedbat | set | messageid: <1554941056.81.0.519333265817.issue36593@roundup.psfhosted.org> |
2019-04-11 00:04:16 | nedbat | link | issue36593 messages |
2019-04-11 00:04:16 | nedbat | create | |
|