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 frominside 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_urlattribute, typicallyAnvilLaunch. The fixture that yieldsforkshould itself bescope="module"orscope="session"— otherwise the snapshot/revert dance buys nothing.- Returns
Generator yielding
Noneonce, then performing the revert on resume.- Raises
RuntimeError – If the
evm_snapshotRPC 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_revertrestores EVM state and storage but does not reset block timestamp. Tests asserting onblock.timestamp == Xmust callevm_setNextBlockTimestampthemselves.See also