https://github.com/algorandfoundation/algorand-python-testing
Unit test your 🐍 smart contracts
https://github.com/algorandfoundation/algorand-python-testing
algokit algorand puya pytest python
Last synced: 3 months ago
JSON representation
Unit test your 🐍 smart contracts
- Host: GitHub
- URL: https://github.com/algorandfoundation/algorand-python-testing
- Owner: algorandfoundation
- License: other
- Created: 2024-07-05T11:58:38.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-03-19T15:03:34.000Z (3 months ago)
- Last Synced: 2025-03-25T23:46:31.236Z (3 months ago)
- Topics: algokit, algorand, puya, pytest, python
- Language: Python
- Homepage: https://algorandfoundation.github.io/algorand-python-testing/
- Size: 944 KB
- Stars: 9
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-algorand - algorand-python-testing - A Python library for unit testing Algorand Python smart contracts without the need to interact with the Algorand blockchain. (Core Resources / AlgoKit)
- awesome-algorand - algorand-python-testing - A Python library for unit testing Algorand Python smart contracts without the need to interact with the Algorand blockchain. (Core Resources / AlgoKit)
README
---
Algorand Python Testing is a companion package to [Algorand Python](https://github.com/algorandfoundation/puya) 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](https://algorandfoundation.github.io/algorand-python-testing/) | [Algorand Python Documentation](https://algorandfoundation.github.io/puya/)
## 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:
1. Ensure you have Python 3.12+
2. Install [AlgoKit CLI](https://github.com/algorandfoundation/algokit-cli?tab=readme-ov-file#install)
3. Install Algorand Python Testing into your project:
```bash
pip install algorand-python-testing
```
4. Create a test file (e.g., `test_contract.py`):```python
from algopy_testing import algopy_testing_context
from your_contract import YourContract
def test_your_contract():
with algopy_testing_context() as context:
# Arrange
contract = YourContract()
expected_result = ... # Your expected result here
# Act
result = contract.your_method(context.any.uint64()) # Your test code here
# Assert
assert result == expected_result
```5. Run your tests using your preferred Python testing framework (e.g., pytest, unittest)
For more detailed information, check out the [full documentation](https://algorandfoundation.github.io/algorand-python-testing/).
## 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](https://algorandfoundation.github.io/algorand-python-testing/examples.html) in the documentation.
## Contributing
We welcome contributions to this project! Please read our [contributing guide](CONTRIBUTING.md) to get started.