Python Testing

  1. Mocking, Patching, and Test Doubles
    1. The Concept of Test Doubles
      1. Dummies
        1. Placeholder Objects
          1. Minimal Implementations
          2. Fakes
            1. Lightweight Implementations
              1. In-Memory Databases
              2. Stubs
                1. Providing Predefined Responses
                  1. State-Based Testing
                  2. Spies
                    1. Recording Interactions
                      1. Behavior Verification
                      2. Mocks
                        1. Verifying Behavior and Calls
                          1. Interaction-Based Testing
                        2. Using unittest.mock
                          1. The Mock and MagicMock Classes
                            1. Creating Mock Objects
                              1. Configuring Return Values and Side Effects
                                1. Mock Attributes and Methods
                                2. The patch Decorator and Context Manager
                                  1. Patching Functions and Objects
                                    1. Scoping Patches
                                      1. Multiple Patches
                                      2. Asserting Mock Calls
                                        1. assert_called_with
                                          1. assert_any_call
                                            1. call_count
                                              1. Inspecting Call Arguments
                                              2. Mock Configuration
                                                1. spec and spec_set Parameters
                                                  1. autospec Usage
                                                    1. Mock Hierarchies
                                                  2. Using the pytest-mock Plugin
                                                    1. The mocker Fixture
                                                      1. Simplifying Mock Creation
                                                        1. Integrating with pytest Fixtures
                                                          1. Mock Lifecycle Management
                                                          2. Spy Functionality
                                                            1. Wrapping Real Objects
                                                              1. Partial Mocking
                                                            2. Advanced Mocking Techniques
                                                              1. Mocking External Dependencies
                                                                1. API Calls
                                                                  1. File System Operations
                                                                    1. Database Connections
                                                                    2. Context Manager Mocking
                                                                      1. Mocking with Statement
                                                                        1. Resource Management Testing
                                                                        2. Property Mocking
                                                                          1. Mocking Class Properties
                                                                            1. Dynamic Property Behavior