Algorand Python Testing is a companion package to Algorand Python that enables efficient unit testing of Algorand Python smart contracts in an offline environment. It emulates key AVM behaviors without requiring a network connection, offering fast and reliable testing capabilities with a familiar Pythonic interface.
Documentation | Algorand Python Documentation
Quick start
The easiest way to use Algorand Python Testing is to instantiate a template with AlgoKit via algokit init -t python
. This will give you a full development environment with testing capabilities built-in.
Alternatively, if you want to start from scratch:
-
Ensure you have Python 3.12+
-
Install AlgoKit CLI
-
Install Algorand Python Testing into your project:
pip install algorand-testing-python
-
Create a test file (e.g., test_contract.py
):
from algopy_testing import algopy_testing_context
from your_contract import YourContract
def test_your_contract():
with algopy_testing_context() as context:
contract = YourContract()
expected_result = ...
result = contract.your_method(context.any.uint64())
assert result == expected_result
-
Run your tests using your preferred Python testing framework (e.g., pytest, unittest)
For more detailed information, check out the full documentation.
Features
- Offline testing environment simulating core AVM functionality
- Compatible with popular Python testing frameworks
- Supports testing of ARC4 contracts, smart signatures, and more
- Provides tools for mocking blockchain state and transactions
Examples
For detailed examples showcasing various testing scenarios, refer to the examples section in the documentation.
Contributing
We welcome contributions to this project! Please read our contributing guide to get started.