Incorrect exception raised with two retrying blocks in function
- Dominant language
- Python
- Stars
- 8.8k
- Forks
- 359
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Description
## Caveats
I've tried to work out what's going on here with Googling, but I've been unsuccessful. I think this is a bug, but appreciate it could be either
- Expected behaviour
- Unsupported use case
It's also unusual for me to use two seperate retrying blocks in the same test case, but the test I'm writing is under development and one will be removed later.
## Minimal Example
```
from unittest import TestCase
from unittest.mock import MagicMock
from tenacity import Retrying, stop_after_attempt
class TestTenacity(TestCase):
def setUp(self):
self.foo = MagicMock(side_effect=[2, 1])
def test_tenacity(self):
for attempt in Retrying(stop=stop_after_attempt(2)):
with attempt:
self.assertEqual(1, self.foo())
for attempt in Retrying(stop=stop_after_attempt(2)):
with attempt:
raise Exception('bippy')
```
### Flow
- retry 0 attempt 0 (`r0a0`) raises
- retry 0 attempt 1 (`r0a1`) does not raise
- retry 1 attempt 0 (`r1a0`) raises
### Expectation
We should see the exception `r1a0` raised, and the unittest comparison should not appear, e.g.
### Reality
The correct exception is raised, but the previous exception has been rendered by unittest comparison, which is very confusing.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.