Fixture and Marker Reference

Brownie includes custom fixtures and markers that can be used when testing your project.

Session Fixtures

These fixtures provide quick access to Brownie objects that are frequently used during testing. If you are unfamiliar with these objects, you may wish to read the documentation listed under “Core Functionality” in the table of contents.


Yields an Accounts container for the active project, used to interact with your local accounts.

1def test_account_balance(accounts):
2    assert accounts[0].balance() == "100 ether"

Short form of the accounts fixture.

1def test_account_balance(a):
2    assert a[0].balance() == "100 ether"

Yields a Chain object, used to access block data and interact with the local test chain.

1def test_account_balance(accounts, chain):
2    balance = accounts[1].balance()
3    accounts[0].transfer(accounts[1], "10 ether")
4    assert accounts[1].balance() == balance + "10 ether"
6    chain.reset()
7    assert accounts[1].balance() == balance

Yields the Contract class, used to interact with contracts outside of the active project.

2def dai(Contract):
3    yield Contract.from_explorer("0x6B175474E89094C44Da98b954EedeAC495271d0F")

Yields a TxHistory container for the active project, used to access transaction data.

1def test_account_balance(accounts, history):
2    accounts[0].transfer(accounts[1], "10 ether")
3    assert len(history) == 1

Yields the InterfaceContainer object for the active project, which provides access to project interfaces.

2def dai(interface):
3    yield interface.Dai("0x6B175474E89094C44Da98b954EedeAC495271d0F")

Callable fixture that provides access to Project objects, used for testing against installed packages.

2def compound(pm, accounts):
3    ctoken = pm('defi.snakecharmers.eth/compound@1.1.0').CToken
4    yield ctoken.deploy({'from': accounts[0]})

Yields the state_machine method, used for running a stateful test.

1def test_stateful(Token, accounts, state_machine):
2    token = Token.deploy("Test Token", "TST", 18, 1e23, {'from': accounts[0]})
4    state_machine(StateMachine, accounts, token)

Yields a Web3 object.

1def test_account_balance(accounts, web3):
2    height = web3.eth.block_number
3    accounts[0].transfer(accounts[1], "10 ether")
4    assert web3.eth.block_number == height + 1

Contract Fixtures

Brownie creates dynamically named fixtures to access each ContractContainer object within a project. Fixtures are generated for all deployable contracts and libraries.

For example - if your project contains a contract named Token, there will be a Token fixture available.

1def test_token_deploys(Token, accounts):
2    token = accounts[0].deploy(Token, "Test Token", "TST", 18, 1e24)
3    assert == "Test Token"

Isolation Fixtures

Isolation fixtures are used to ensure a clean test environment when running tests, and to prevent the results of a test from affecting subsequent tests. See Isolation Fixtures for information on how to use these fixtures.


Resets the local chain before running and after completing the test module.


Takes a snapshot of the chain before running a test and reverts to it after the test completes.


Brownie provides the following markers for use within your tests:


Mark a test so that it only runs if the active network is named network_name. This is useful when you have some tests intended for a local development environment and others for a forked mainnet.

2def test_almost_in_prod():
3    pass

Only evaluate coverage for transactions made during this test, not calls.

This marker is useful for speeding up slow tests that involve many calls to the same view method.

1def test_normal(token):
2    # during coverage analysis this call is handled as a transaction
3    assert token.balanceOf(accounts[0]) == 900
6def test_no_call_cov(Token):
7    # this call is handled as a call, the test execution is quicker
8    assert token.balanceOf(accounts[1]) == 100

Skips a test if coverage evaluation is active.

2def test_heavy_lifting():
3    pass