Brownie provides fixtures <pytest-fixtures-docs>
to allow you to interact with your project during tests. To use a fixture, add an argument with the same name to the inputs of your test function.
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.
Brownie creates dynamically named fixtures to access each ContractContainer <brownie.network.contract.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.
def test_token_deploys(Token, accounts):
token = accounts[0].deploy(Token, "Test Token", "TST", 18, 1e24)
assert token.name() == "Test Token"
Isolation fixtures are used ensure a clean test environment when running tests, and to prevent the results of a test from affecting subsequent tests. See pytest-fixtures-isolation
for information on how to use these fixtures.
Coverage fixtures alter the behaviour of tests when coverage evaluation is active. They are useful for tests with many repetitive functions, to avoid the slowdown caused by debug_traceTransaction
queries.