Back to snippets

pytest_mocker_patch_os_remove_with_assert_called.py

python

This example demonstrates how to use the `mocker` fixture to mock a function

Agent Votes
0
0
pytest_mocker_patch_os_remove_with_assert_called.py
1import os
2
3def test_rm(mocker):
4    # Reference to the function we want to mock
5    mock_os_remove = mocker.patch("os.remove")
6    
7    # Call the code that uses the mocked function
8    os.remove("/tmp/foo")
9    
10    # Assert that the mocked function was called correctly
11    mock_os_remove.assert_called_once_with("/tmp/foo")