How damianb-bitflipper/algopytest works
Project Type and Purpose
• This is a Python library/Pytest plugin (not a web server or UI) whose sole purpose is to simplify writing tests for Algorand smart contracts by providing ready-made fixtures and helper functions.
• It acts as a middleware between Pytest and an Algorand sandbox, hiding boilerplate for account setup, contract deployment, transactions, and cleanup.
Key Architectural Components
From the file tree and README, the main subsystems are:
a. Plugin Core (algopytest package)
• account_ops.py – account creation/funding/cleanup
• client_ops.py – Algod client creation, SDK wrappers
• transaction_ops.py – building/submitting transactions
• config_params.py – reading environment variables (SANDBOX_DIR, INITIAL_FUNDS_ACCOUNT, etc.)
• fixtures.py – Pytest hook registrations, fixture definitions (owner, user1, smart_contract_id, etc.)
• entities.py, utils.py, type_stubs.py – supporting data models, helpers, and typing
b. External Dependencies
• Algorand Sandbox (Docker-based local network)
• Algorand SDK (algosdk)
• Pytest (test runner and plugin host)
c. Demos
• A set of sample projects under /demos illustrating how end-users consume the plugin
d. Documentation & CI
• docs/ – Read-the-Docs source for docs generation
• .github/workflows/ci.yml – GitHub Actions for tests, linting, coverage
• pre-commit, mypy, flake8 configs for quality checks
Interactions and Data Flows
• Pytest test suite invokes fixtures provided by AlgoPytest (via pytest_plugin hooks in fixtures.py).
• A fixture (e.g. smart_contract_id) calls create_app (in client_ops) which:
1. Reads config_params to find SANDBOX_DIR and INITIAL_FUNDS_ACCOUNT
2. Uses account_ops to create/fund user accounts
3. Deploys the approval/clear programs to the sandbox via Algod client (client_ops + transaction_ops)
4. Yields an app_id back to the test
5. On teardown, runs cleanup (delete app, close accounts)
• Tests (in /tests or individual demos) call helper functions (update_app, call_app, opt_in_app) which invoke transaction_ops and client_ops against the sandbox.
• The docs build system reads the same modules to generate reference docs.
Highlighted Architectural Patterns & Principles
• Plugin Pattern: leveraging pytest hooks to auto-register fixtures
• Dependency Injection via fixtures: injecting clients, accounts, app_ids into tests
• Clean-up via context managers/yield fixtures to guarantee teardown
• Separation of concerns:
• config_params only reads env vars
• account_ops only manages accounts
• transaction_ops only builds and submits transactions
• Extensibility: new fixtures or helpers can be added in fixtures.py or new modules