# TypeError: test_foo() 缺少 1 个必需的位置参数: 'mock_bar'

- **ID:** `python/unittest-mock-patch-decorator-order`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用多个 @patch 装饰器时，mock 按从下到上的顺序传递。如果测试函数签名不匹配，会发生 TypeError。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   @patch('module.ClassB')
@patch('module.ClassA')
def test_foo(mock_a, mock_b):  # mock_a corresponds to bottom decorator
    ...
   ```
2. **** (98% 成功率)
   ```
   def test_foo():
    with patch('module.ClassA') as mock_a, \
         patch('module.ClassB') as mock_b:
        ...
   ```

## 无效尝试

- **** — This hides the error but makes the test less clear and may cause issues with assertions. (70% 失败率)
- **** — This may not be possible if multiple dependencies need mocking. (60% 失败率)
