🔥 BLACK FRIDAY SALE1 course ₹199·any 3 courses ₹399 for 3 months·ALL courses + 1 mock interview ₹599 for 6 monthsClaim offer →

Python · Quality, Errors and Testing · Intermediate · 30 min read

Python Mocking, Fixtures and Property-Based Testing: unittest.mock, pytest Fixtures, Fakes and Hypothesis

Test code that has dependencies. Learn when to mock, stub, fake or spy, unittest.mock and patch placement rules, autospec, side effects, pytest fixtures with scopes and factories, monkeypatch, tmp_path and capsys, test doubles for time, files, HTTP and databases, dependency injection for testability, property-based testing with Hypothesis (strategies, shrinking, stateful tests) and how to keep a fast, trustworthy suite.

Python Mocking, Fixtures and Property-Based Testing: unittest.mock, pytest Fixtures, Fakes and Hypothesis: lesson illustration

A first look

  • Intermediate level · 30 min read
  • 7 interview questions with model answers
  • Quality, Errors and Testing · Python Mastery

You will learn to

  • The test-double vocabulary: dummy, stub, fake, mock, spy
  • unittest.mock: Mock, MagicMock, patch (where to patch!), autospec, sideeffect
  • pytest fixtures: scopes, factories, yield teardown, conftest.py, monkeypatch
  • …and 3 more topics inside
Create an account to start

Create a free account to see what this lesson covers

  • Every free lesson in every section, in full
  • Track your progress and pick up where you left off
  • Free practice questions and an incident simulation
  • Takes under a minute: name, email and a password

No card needed. Full access to Python is a paid upgrade you can choose later.