Unit Testing with Requests
summary
A practical how-to: requests-mock gives real requests.Response objects (status, raise_for_status, cookies), matches by URL/method/headers or regex, supports queued responses, exceptions and a history you can assert against; Betamax records a requests.Session to a cassette file (first run 9s, replay 0.2s, cassette ~200K JSON), supports placeholders for tokens and record modes. Tradeoffs: mocking tests exact protocol and edge cases, cassettes capture real behavior but can go stale when remote data changes.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 0:44The challenge of API testing
- 1:54Core testing concepts
- 2:50Understanding mocking
- 5:03Introducing requests-mock
- 15:34Betamax overview
- 16:39Implementing Betamax
- 22:31Trade-offs and best practices
- 25:00Q&A and closing
related talks
49mFor those about to Mock I salute you!
27mEffectively Testing Services
29mUnit testing in the real world with mock
20mTDD with WebMock
28mTesting HTTP APIs in Ruby
46mFrom Betamax to VCR: harden your API integration testing
39mIntro to Mocking: Why Unit Testing Doesn't Have To Be So Hard
51mFramework agnostic REST api testing
