# pytest.fail('Test failed due to timeout') -> Failed: Test failed due to timeout

- **ID:** `python/pytest-fail-with-message`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The test explicitly calls pytest.fail() with a custom message, which immediately stops the test and reports a failure, often used for conditional checks that are not covered by standard assertions.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 7.0.0 | active | — | — |
| 8.0.0 | active | — | — |

## Workarounds

1. **Use pytest.fail() with a descriptive message to provide context for the failure** (95% success)
   ```
   if condition:
    pytest.fail('Expected condition to be False, but it was True')
This makes the test output clear.
   ```
2. **Replace with a custom assertion using pytest.assume for non-fatal failures** (70% success)
   ```
   from pytest import assume
assume(not condition, 'Condition should be False')
This allows the test to continue but still report the failure.
   ```

## Dead Ends

- **Replacing pytest.fail() with a simple print statement** — This does not stop the test or report failure, so the test may pass even if the condition is met. (80% fail)
- **Using assert False instead of pytest.fail()** — This works but provides less descriptive error messages, making debugging harder. (30% fail)
