| 8 | |
| 9 | |
| 10 | class IndexOnce: |
| 11 | def __init__(self, value): |
| 12 | self.value = value |
| 13 | self.calls = 0 |
| 14 | |
| 15 | def __index__(self): |
| 16 | self.calls += 1 |
| 17 | if self.calls > 1: |
| 18 | raise AssertionError("count evaluated twice") |
| 19 | return self.value |
| 20 | |
| 21 | |
| 22 | @pytest.mark.parametrize("count", [2, 1, 0, -2]) |
no outgoing calls