This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nedbat
Recipients nedbat
Date 2019-04-11.00:04:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554941056.81.0.519333265817.issue36593@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-04-11 00:04:16nedbatsetrecipients: + nedbat
2019-04-11 00:04:16nedbatsetmessageid: <1554941056.81.0.519333265817.issue36593@roundup.psfhosted.org>
2019-04-11 00:04:16nedbatlinkissue36593 messages
2019-04-11 00:04:16nedbatcreate