Registry / testing / pytest-wake

pytest-wake

JSON →
library0.4.3pypypi✓ verified 24d ago

pytest-wake is a pytest plugin that integrates the Wake Solidity development and fuzz testing framework with the pytest testing framework. It enables writing tests for Solidity smart contracts using Python, leveraging pytest's capabilities and Wake's `pytypes` for type-safe interactions. The current version is 0.4.3, released on November 19, 2024. While specific release cadence details for `pytest-wake` are not explicitly stated, its development is tied to the active Wake framework.

pip install pytest-wake eth-wake
INSTALL
IMPORT
SIG · PYTEST-WAKE
P
pytest-wake
testingpythonv0.4.3
Install
19.3s avg
Import
424ms
Disk
173MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 20.1s
py 3.11
✓ —
✓ 18.1s
py 3.12
✓ —
✓ 17.2s
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 21.8s
173MB installed
● package 173MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest
import pytest
Users primarily import pytest and interact with Wake through generated pytypes or Wake's CLI commands that integrate with pytest.
GeneratedContractPytype
from pytypes.contracts.MyContract import MyContract
Wake generates Python-native 'pytypes' from Solidity contracts, which are then imported and used in pytest tests. The exact import path depends on your project structure and contract names.

This quickstart demonstrates how to set up a basic `pytest` test for a Solidity smart contract using the `Wake` framework. First, create a `contracts/MyContract.sol` file with a simple Solidity contract. Then, initialize a Wake project and generate Python `pytypes` by running `wake init` and `wake pytypes -w` in your project's root directory. These commands set up the project structure and create Python classes (pytypes) that represent your Solidity contracts, enabling type-safe interaction. Finally, write a `pytest` test file (e.g., `test_my_contract.py`) that imports and uses these generated pytypes to interact with and assert properties of your deployed contract.

import pytest import os # Assuming a file `contracts/MyContract.sol` exists with a simple contract: # pragma solidity ^0.8.0; # contract MyContract { # uint public value; # constructor(uint _value) { value = _value; } # function setValue(uint _newValue) public { value = _newValue; } # } # You would typically run 'wake init' and 'wake pytypes' in your project root # to generate the 'pytypes' directory before running tests. # For example: wake init --force; wake pytypes -w # These imports would be generated by 'wake pytypes' # For this example, we'll assume a basic contract structure and manual pytype creation # In a real scenario, Wake's CLI would manage this. # To make this runnable without `wake pytypes` output, we will mock the contract interaction slightly. try: from pytypes.contracts.MyContract import MyContract # In a real setup, you'd also need a 'default_chain' fixture provided by Wake # For demonstration, we'll simulate contract deployment and interaction. class MockContract: def __init__(self, value): self._value = value @property def value(self): return self._value def setValue(self, new_value): self._value = new_value return self # Simulate fluent interface # This fixture would typically be provided by Wake @pytest.fixture def deployed_my_contract(): # In a real Wake test, this would deploy your contract to a chain # and return the pytype instance connected to it. return MockContract(10) def test_my_contract_initial_value(deployed_my_contract): assert deployed_my_contract.value == 10 def test_my_contract_set_value(deployed_my_contract): deployed_my_contract.setValue(20) assert deployed_my_contract.value == 20 except ImportError: print("Skipping contract tests: 'pytypes' not generated or Wake environment not set up.") print("Please run 'wake init' and 'wake pytypes -w' in your project directory.") def test_placeholder_contract(): pytest.skip("Contract pytypes not available, Wake environment not set up.")
Debug
Known issues
gotchaWhen Wake generates Python 'pytypes' from Solidity contracts, name collisions can occur if a Solidity type name is a Python keyword or reserved name. In such cases, Wake appends an underscore to the generated Python type name (e.g., `class` becomes `class_`). Overloaded Solidity functions also result in appended underscores (e.g., `foo` and `foo_`).
fix
Be aware of Python reserved keywords and overloaded function names in your Solidity contracts. Check the generated `pytypes` files for exact class and method names if you encounter import or attribute errors.
affects: All versions
gotchapytest's test discovery mechanism relies on specific file and function naming conventions (e.g., `test_*.py` or `*_test.py` for files, and `test_*` for functions/methods). Incorrect naming can lead to tests not being found or executed by pytest, even if `pytest-wake` is installed.
fix
Always follow pytest's standard naming conventions for test files and functions. Refer to the pytest documentation on test discovery for more details. Ensure that `__init__.py` files are present in directories you intend to be treated as Python packages for correct module import by pytest.
affects: All versions
breakingAs a pytest plugin, `pytest-wake`'s functionality is dependent on the installed `pytest` version. Major `pytest` releases (e.g., `pytest 8.0`, `pytest 9.0`) often introduce breaking changes to their API or internal mechanisms that could affect plugins. If `pytest-wake` is not updated to support a new major `pytest` version, it may lead to unexpected behavior or failures.
fix
Always check the `pytest-wake` release notes or documentation for compatibility with specific `pytest` versions before upgrading `pytest`. Pin your `pytest` version in your `requirements.txt` to a known compatible version if necessary (e.g., `pytest<8.0` if `pytest-wake` does not yet support `pytest 8.x`).
affects: Dependent on pytest versions 8.0+, 9.0+
Upgrade
Version history
0.4.3latest on PyPI · released Nov 19, 2024
Audit
Dependencies
pytestrequiredpytest-wake is a plugin for pytest, extending its functionality for Solidity contract testing.
eth-wakerequiredpytest-wake integrates the Wake framework; eth-wake provides the core Solidity development and testing functionalities, including 'pytypes' generation.
Agent activity
7 hits · last 30 days
node
6
Resources
pytest-wake — pip install pytest-wake · libregistry