'isinstance mocked pythonnet class
I am making some python unit tests over classes which import C# with pythonnet, but mocks of those imported elements do not pass isinstance() tests.
Code under test:
import clr
clr.AddReference('MyDll')
from MyDll import ClassNet
def check(object_net):
assert isinstance(object_net, ClassNet) # <-- fails
...
Test code:
import unittest
from unittest.mock import MagicMock
from MyCode import check
class Test(unittest.TestCase):
def test(self):
mock_object = MagicMock(spec=ClassNet)
check(mock_object)
Test fails because isinstance return false although spec argument has been used. Based on Mock Doc:
If spec is an object (rather than a list of strings) then __class__ returns the class of the spec object. This allows mocks to pass isinstance() tests.
Any idea whether I am missing something?
Debugging, ClassNet is a CLR Metatype, but I don't know if this has something to do with it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
