[Query] How to propagate the underlying assertion error message from tenacity?
- Dominant language
- Python
- Stars
- 8.8k
- Forks
- 359
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
I am using tenacity 9.0.0 with Python 3.9. My code is like below
```
@pytest.mark.monitoring_service
def test():
@retry(stop=stop_after_attempt(6), wait=wait_fixed(5))
def assert_response():
logging.info("Retrying get flow logs")
es.indices.refresh(index='monitoring')
response = requests.get(url, headers=headers, json=data, params=params)
assert response.status_code == 200, f"Response status is {response.status_code} and body: {response.text}"
response_json = response.json()
logging.info("Response: " + str(response_json))
assert response_json['meta']['run_id'] == 1742403068092, "run_id does not match"
try:
assert_response()
except RetryError as e:
underlying_error = e.last_attempt.exception()
error_message = str(underlying_error)
logging.error(f"Failed to get flow logs after retries: {underlying_error}")
raise AssertionError(f"Failed to get flow logs after multiple retries: {error_message}") from underlying_error
```
I am seeing the error logs like below when retry gets exhausted.
```
integration-tests-1 | FAILED test_apps/monitoring_service/test_es_monitoring_dao.py::test - AssertionError: Failed to get flow logs after multiple retries: 'run_id'
integration-tests-1 | ====================== 1 failed, 130 deselected in 11.42s ======================
integration-tests-1 | Result of the pytest script: 1
```
How can I get the underlying log `run_id does not match` ?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.