evm_snapshot_revert

Documentation for eth_defi.testing.evm_snapshot_fixture.evm_snapshot_revert function.

evm_snapshot_revert(fork)

Snapshot EVM state before, revert after — generator helper for autouse fixtures.

Yields once after taking the snapshot, then reverts on resume. Designed to be used with yield from inside a per-file @pytest.fixture(autouse=True) so each test sees a clean state on a module-scope Anvil fork.

Parameters

fork – Object with a json_rpc_url attribute, typically AnvilLaunch. The fixture that yields fork should itself be scope="module" or scope="session" — otherwise the snapshot/revert dance buys nothing.

Returns

Generator yielding None once, then performing the revert on resume.

Raises

RuntimeError – If the evm_snapshot RPC call returns a non-result (e.g. an older Anvil build or a non-Anvil backend snuck in via a different fixture).

Return type

collections.abc.Iterator[None]

Note

evm_revert restores EVM state and storage but does not reset block timestamp. Tests asserting on block.timestamp == X must call evm_setNextBlockTimestamp themselves.