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

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

## 根因

多个 @patch 装饰器按从下到上的顺序注入 mock，但测试签名按从上到下列出，导致参数绑定错误。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   @patch('myapp.db.open')
@patch('myapp.fs.read')
def test_foo(mock_read, mock_open):
    # mock_read corresponds to the bottom decorator
    ...
   ```
2. **** (90% 成功率)
   ```
   def test_foo():
    with patch('myapp.fs.read') as mock_read, \
         patch('myapp.db.open') as mock_open:
        ...
   ```

## 无效尝试

- **** — Fixes one test but the convention is undocumented; other tests in the file break the same way. (50% 失败率)
- **** — Mocks are positional; *args swallows them but makes assertions awkward and hides binding bugs. (60% 失败率)
