The key object in every test is a strategy. A strategy is a recipe for describing the sort of data you want to generate. Brownie provides a strategy method that generates strategies for any given ABI type.
- Fixtures executed
- Before each test a chain.snapshot() is created
- Generate values from strategy
- Test is executed
- Chain reverted to snapshot
- Repeat 50 times or until failure
- Teardown of fixtures
from brownie.test import given, strategy
@given(my_var=strategy(<strategy type>, <parameters>))
def test_basic_example(my_var):
...
By default Brownie will execute 50 strategies per test, can be changed in brownie-config.yaml or by applying a @settings
decorator
@settings(max_examples=500)
@given(strategy(...))
def test_larger_example(...):
...
You can exclude a directory from being executed by pytest by creating a setup.cfg
file
[tool:pytest]
norecursedirs=<dir>
Brownie can generate strategies based on multiple ABI types. More details at the Brownie documentation