Skip to content

Commit a2f95e1

Browse files
committed
Add test_mock_new()
1 parent c89561f commit a2f95e1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_class.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from unittest import mock
2+
13
import pytest
24

35
import env
@@ -203,6 +205,18 @@ def __init__(self):
203205
assert msg(exc_info.value) == expected
204206

205207

208+
@pytest.mark.parametrize(
209+
"mock_return_value", [None, (1, 2, 3), m.Pet("Polly", "parrot"), m.Dog("Molly")]
210+
)
211+
def test_mock_new(mock_return_value):
212+
with mock.patch.object(
213+
m.Pet, "__new__", return_value=mock_return_value
214+
) as mock_new:
215+
obj = m.Pet("Noname", "Nospecies")
216+
assert obj is mock_return_value
217+
mock_new.assert_called_once_with(m.Pet, "Noname", "Nospecies")
218+
219+
206220
def test_automatic_upcasting():
207221
assert type(m.return_class_1()).__name__ == "DerivedClass1"
208222
assert type(m.return_class_2()).__name__ == "DerivedClass2"

0 commit comments

Comments
 (0)