DiscoverTest & Code226: pytest-mock : Mocking in pytest
226: pytest-mock : Mocking in pytest

226: pytest-mock : Mocking in pytest

Update: 2025-01-31
Share

Description

pytest-mock is currently the #3 pytest plugin. 
pytest-mock is a wrapper around unittest.mock.

In this episode:

  • Why the pytest-mock plugin is awesome
  • What is mocking, patching, and monkey patching
  • What, if any, is the difference between mock, fake, spy, stub. 
  • Why we might need these in testing
  • Some history of mock in Python and how mock became unittest.mock
  • From unittest.mock
    • patch.object
    • patch.object with autospec
    • using these as context managers
  • pytest-mock:
    • The mocker fixture 
    • Cleanup in teardown
    • Using mocker.patch, mocker.spy, and mocker.stub
    • Why it's awesome and why you might want to use it over straight unittest.mock

Links:





Comments 
00:00
00:00
x

0.5x

0.8x

1.0x

1.25x

1.5x

2.0x

3.0x

Sleep Timer

Off

End of Episode

5 Minutes

10 Minutes

15 Minutes

30 Minutes

45 Minutes

60 Minutes

120 Minutes

226: pytest-mock : Mocking in pytest

226: pytest-mock : Mocking in pytest

Brian Okken