Skip to content

Commit

Permalink
fix(pytest): fix double yield problem in isolation fixture [APE-1353] (
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 31, 2023
1 parent 26a3960 commit dbd6401
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ape/pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ def _isolation(self) -> Iterator[None]:
snapshot_id = None

if self._track_transactions:
did_yield = False
try:
with self.receipt_capture:
yield
did_yield = True

except BlockNotFoundError:
yield
if not did_yield:
# Prevent double yielding.
yield

else:
yield
Expand Down
31 changes: 31 additions & 0 deletions tests/functional/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from ape.exceptions import BlockNotFoundError
from ape.pytest.fixtures import PytestApeFixtures


@pytest.fixture
def receipt_capture(mocker):
return mocker.MagicMock()


@pytest.fixture
def fixtures(mocker, receipt_capture):
return PytestApeFixtures(mocker.MagicMock(), receipt_capture)


@pytest.fixture
def isolation(fixtures):
return fixtures._isolation()


def test_isolation(isolation, receipt_capture):
# Set up receipt capture to fail on __exit__
# AFTER the yield statement. There was a bug
# where we got a double-yield in this situation.

receipt_capture.__exit__.side_effect = BlockNotFoundError(0)

assert next(isolation) is None
with pytest.raises(StopIteration):
next(isolation)

0 comments on commit dbd6401

Please sign in to comment.