mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
Add test_mock_new()
This commit is contained in:
parent
c89561f77a
commit
a2f95e1d94
@ -1,3 +1,5 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import env
|
||||
@ -203,6 +205,18 @@ def test_inheritance_init(msg):
|
||||
assert msg(exc_info.value) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_return_value", [None, (1, 2, 3), m.Pet("Polly", "parrot"), m.Dog("Molly")]
|
||||
)
|
||||
def test_mock_new(mock_return_value):
|
||||
with mock.patch.object(
|
||||
m.Pet, "__new__", return_value=mock_return_value
|
||||
) as mock_new:
|
||||
obj = m.Pet("Noname", "Nospecies")
|
||||
assert obj is mock_return_value
|
||||
mock_new.assert_called_once_with(m.Pet, "Noname", "Nospecies")
|
||||
|
||||
|
||||
def test_automatic_upcasting():
|
||||
assert type(m.return_class_1()).__name__ == "DerivedClass1"
|
||||
assert type(m.return_class_2()).__name__ == "DerivedClass2"
|
||||
|
Loading…
Reference in New Issue
Block a user