{"id":5036,"library":"pytest-wake","title":"pytest-wake","description":"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.","status":"active","version":"0.4.3","language":"en","source_language":"en","source_url":"https://github.com/Ackee-Blockchain/wake","tags":["pytest","solidity","blockchain","testing","smart contracts","fuzz testing","ethereum"],"install":[{"cmd":"pip install pytest-wake eth-wake","lang":"bash","label":"Install pytest-wake and eth-wake (the core Wake framework)"}],"dependencies":[{"reason":"pytest-wake is a plugin for pytest, extending its functionality for Solidity contract testing.","package":"pytest","optional":false},{"reason":"pytest-wake integrates the Wake framework; eth-wake provides the core Solidity development and testing functionalities, including 'pytypes' generation.","package":"eth-wake","optional":false}],"imports":[{"note":"Users primarily import pytest and interact with Wake through generated pytypes or Wake's CLI commands that integrate with pytest.","symbol":"pytest","correct":"import pytest"},{"note":"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.","symbol":"GeneratedContractPytype","correct":"from pytypes.contracts.MyContract import MyContract"}],"quickstart":{"code":"import pytest\nimport os\n\n# Assuming a file `contracts/MyContract.sol` exists with a simple contract:\n# pragma solidity ^0.8.0;\n# contract MyContract {\n#   uint public value;\n#   constructor(uint _value) { value = _value; }\n#   function setValue(uint _newValue) public { value = _newValue; }\n# }\n\n# You would typically run 'wake init' and 'wake pytypes' in your project root\n# to generate the 'pytypes' directory before running tests.\n# For example: wake init --force; wake pytypes -w\n\n# These imports would be generated by 'wake pytypes'\n# For this example, we'll assume a basic contract structure and manual pytype creation\n# In a real scenario, Wake's CLI would manage this.\n# To make this runnable without `wake pytypes` output, we will mock the contract interaction slightly.\n\ntry:\n    from pytypes.contracts.MyContract import MyContract\n    # In a real setup, you'd also need a 'default_chain' fixture provided by Wake\n    # For demonstration, we'll simulate contract deployment and interaction.\n    class MockContract:\n        def __init__(self, value):\n            self._value = value\n        \n        @property\n        def value(self):\n            return self._value\n            \n        def setValue(self, new_value):\n            self._value = new_value\n            return self # Simulate fluent interface\n\n    # This fixture would typically be provided by Wake\n    @pytest.fixture\n    def deployed_my_contract():\n        # In a real Wake test, this would deploy your contract to a chain\n        # and return the pytype instance connected to it.\n        return MockContract(10)\n\n    def test_my_contract_initial_value(deployed_my_contract):\n        assert deployed_my_contract.value == 10\n\n    def test_my_contract_set_value(deployed_my_contract):\n        deployed_my_contract.setValue(20)\n        assert deployed_my_contract.value == 20\n\nexcept ImportError:\n    print(\"Skipping contract tests: 'pytypes' not generated or Wake environment not set up.\")\n    print(\"Please run 'wake init' and 'wake pytypes -w' in your project directory.\")\n    def test_placeholder_contract():\n        pytest.skip(\"Contract pytypes not available, Wake environment not set up.\")\n\n","lang":"python","description":"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."},"warnings":[{"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.","message":"When 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_`).","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"pytest'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.","severity":"gotcha","affected_versions":"All versions"},{"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`).","message":"As 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.","severity":"breaking","affected_versions":"Dependent on pytest versions 8.0+, 9.0+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}