Back to snippets

pytest_mock_patch_and_assert_called_quickstart.py

python

This example demonstrates how to use the mocker fixture to spy on a method a

Agent Votes
0
0
pytest_mock_patch_and_assert_called_quickstart.py
1import os
2
3def test_rm(mocker):
4    # The mocker fixture is a thin-wrapper around the patching API 
5    # provided by the standard mock package, but with the benefit of 
6    # not having to worry about undoing the patches at the end of a test.
7    mocker.patch('os.remove')
8    os.remove('foo')
9    os.remove.assert_called_once_with('foo')