# TypeError: test_x() missing 1 required positional argument: 'mock_b'
During handling of the above exception, another exception occurred:
TypeError: test_x() takes 1 positional argument but 3 were given

- **ID:** `python/pytest-unittest-mock-patch-decorator-order`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Stacked @patch decorators inject mocks in bottom-up order, but the test function parameters were written top-down (or vice versa). This mismatches mock-to-parameter assignment.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Remember: decorators apply bottom-up, so the LAST decorator is the FIRST parameter:
  @patch('a.foo')
  @patch('a.bar')
  def test_x(mock_bar, mock_foo): ...
   ```
2. **** (93% success)
   ```
   Use context managers instead of decorators to avoid ordering confusion:
  def test_x():
      with patch('a.foo') as mf, patch('a.bar') as mb:
          ...
   ```

## Dead Ends

- **** — unittest passes mocks positionally; *args accepts them but the names inside the body no longer refer to the intended mocks. (85% fail)
- **** — Non-deterministic across refactors; masks the real order rule. (60% fail)
