# AssertionError: assert '' == 'hello\n'
  - 
  + hello

- **ID:** `python/pytest-capsys-flush-buffering`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

`capsys.readouterr()` returns empty because the code under test uses `print(..., flush=False)` and the buffer has not been flushed, or it writes to `sys.__stdout__` instead of `sys.stdout`.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.x | active | — | — |
| 8.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Force flush in the code under test or use print(..., flush=True):

print('hello', flush=True)
   ```
2. **** (90% success)
   ```
   Use capfd and ensure the code writes to sys.stdout:

def test_out(capfd):
    my_func()
    out, err = capfd.readouterr()
    assert out == 'hello\n'
   ```

## Dead Ends

- **** — Flushing is not time-based; the buffer may still be unflushed and the test is now flaky. (80% fail)
- **** — capfd captures file descriptors; if the code uses sys.__stdout__ directly it still bypasses both. (60% fail)
