-
-
Notifications
You must be signed in to change notification settings - Fork 150
Closed
Description
Python version: 3.7.3
Packages on my machine:
- pytest: 5.2.1
- pytest-mock: 1.11.1
Testing a patched object method is called will fail using pytest_mock
:
import pytest
from pytest_mock import mocker
def test_process_is_saved_to_db(mocker):
with mocker.patch.object(Process, 'save', return_value="it works") as mock_save:
thing = Process()
thing.save()
mock_save.assert_called_once()
AssertionError: Expected 'mock' to have been called once. Called 0 times.
But will pass with the exact same signature using unittest.mock
:
import pytest
from unittest.mock import patch
def test_process_is_saved_to_db():
with patch.object(Process, 'save', return_value="it works") as mock_save:
thing = Process()
thing.save()
mock_save.assert_called_once()
All tests passed
Metadata
Metadata
Assignees
Labels
No labels