Useful Links
Computer Science
Cybersecurity
Python Testing
1. Fundamentals of Software Testing
2. Python Testing Environment Setup
3. The unittest Framework
4. The pytest Framework
5. Test Design and Best Practices
6. Mocking, Patching, and Test Doubles
7. Advanced Testing Techniques
8. Testing Specific Application Types
9. Test Automation and Continuous Integration
10. Code Coverage
11. Security-Oriented Testing
12. Test Data Management
13. Debugging and Troubleshooting Tests
14. Performance and Optimization
Mocking, Patching, and Test Doubles
The Concept of Test Doubles
Dummies
Placeholder Objects
Minimal Implementations
Fakes
Lightweight Implementations
In-Memory Databases
Stubs
Providing Predefined Responses
State-Based Testing
Spies
Recording Interactions
Behavior Verification
Mocks
Verifying Behavior and Calls
Interaction-Based Testing
Using unittest.mock
The Mock and MagicMock Classes
Creating Mock Objects
Configuring Return Values and Side Effects
Mock Attributes and Methods
The patch Decorator and Context Manager
Patching Functions and Objects
Scoping Patches
Multiple Patches
Asserting Mock Calls
assert_called_with
assert_any_call
call_count
Inspecting Call Arguments
Mock Configuration
spec and spec_set Parameters
autospec Usage
Mock Hierarchies
Using the pytest-mock Plugin
The mocker Fixture
Simplifying Mock Creation
Integrating with pytest Fixtures
Mock Lifecycle Management
Spy Functionality
Wrapping Real Objects
Partial Mocking
Advanced Mocking Techniques
Mocking External Dependencies
API Calls
File System Operations
Database Connections
Context Manager Mocking
Mocking with Statement
Resource Management Testing
Property Mocking
Mocking Class Properties
Dynamic Property Behavior
Previous
5. Test Design and Best Practices
Go to top
Next
7. Advanced Testing Techniques