# TypeError: a bytes-like object is required, not 'str' in capsys.readouterr()

- **ID:** `python/pytest-capture-output-binary`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Using capsys (which captures text) to capture binary output from sys.stdout.buffer, causing a type mismatch when the code writes bytes.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use capfd (capture file descriptors) instead of capsys to capture both text and binary output: out, err = capfd.readouterr()
   ```
2. **** (85% success)
   ```
   If the output is binary, use sys.stdout.buffer.write() and capture with capfd, then decode as needed.
   ```

## Dead Ends

- **** — Using capfd instead of capsys may work for binary but fails if the test also needs to capture text from sys.stdout. (50% fail)
- **** — Decoding bytes to str before assertion may mask encoding issues in the output. (40% fail)
