The accounts fixture provides access to automatically funded test accounts. You can access them by index or by address.
Accessing Accounts
- By Index:
accounts[0], accounts[1], etc. - By Address (Impersonation): If using a provider like Foundry, you can access an account via its address:
accounts["0x... "]. Alternatively, use accounts.impersonate_account("0x...") for better readability.
Configuration
You can configure test accounts in ape-config.yaml using the test key:
test:
mnemonic: test test test test test test test test test test test junk
number_of_accounts: 5
balance: 100_000 ETH
hd_path: "m/44'/60'/0'/0/{}" # Optional: custom derivation path
Best Practice
For cleaner tests, wrap the accounts fixture into your own named fixtures (e.g., owner, receiver).
def test_my_method(accounts):
owner = accounts[0]
receiver = accounts[1]
# Recommended pattern
@pytest.fixture
def owner(accounts):
return accounts[0]
@pytest.fixture
def receiver(accounts):
return accounts[1]
def test_my_method(owner, receiver):
...
# Impersonation pattern
@pytest.fixture
def vitalik(accounts):
return accounts.impersonate_account("0xab5801a7d398351b8be11c439e05c5b3259aec9b")