# AssertionError: assert '' == 'expected output'
  - expected output
  + 

- **ID:** `python/pytest-capture-stdout-not-shown`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The test captures stdout via capsys but the code under test writes to a logger or to sys.__stdout__ instead of sys.stdout, or capsys was requested after the output was already flushed. capsys only captures writes through sys.stdout at call time.

## Version Compatibility

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

## Workarounds

1. **** (92% success)
   ```
   def test_logs(caplog):
    with caplog.at_level('INFO'):
        run_task()
    assert 'expected output' in caplog.text
   ```
2. **** (90% success)
   ```
   def test_prints(capsys):
    print('expected output')
    captured = capsys.readouterr()
    assert captured.out.strip() == 'expected output'
   ```

## Dead Ends

- **** — capsysbinary only changes the encoding of captured bytes; it still won't capture logger output or writes to sys.__stdout__. (70% fail)
- **** — Flushing does not redirect output into the capture buffer if the code wrote to a different stream. (65% fail)
