Skip to content

Coverage analysis#

Woke supports code coverage analysis of both Python test scripts and Solidity contracts.

Python scripts coverage#

In order to measure coverage of Python scripts executed using woke test, the pytest-cov plugin can be used.

pip3 install pytest-cov

To analyze scripts located in the tests directory, run:

$ woke test -- --cov=tests

---------- coverage: platform linux, python 3.7.12-final-0 -----------
Name                                 Stmts   Miss  Cover
tests/                        0      0   100%
tests/                   36      4    89%
tests/              34      0   100%
tests/      23      4    83%
tests/                63      0   100%
TOTAL                                  156      8    95%

Note that the -- is required to separate the arguments passed to woke from the arguments passed to pytest.


There is no such option for woke fuzz since it does not use pytest internally.

Solidity contracts coverage#

Woke comes with a built-in coverage analysis module that can be activated by passing the --coverage flag and, in the case of woke fuzz, an optional number of processes to collect coverage data from.

woke test --coverage

By passing the --coverage flag to woke fuzz without specifying the number of processes, the coverage analysis is performed for all fuzzing processes.

woke fuzz -n 4 --coverage 2

There are some limitations to this coverage analysis:

  • code coverage can be inaccurate when analyzing a project with the solc optimizer enabled,
  • multiple executions of the same function in the same transaction/call are counted as a single execution,
  • call requests (default for pure and view functions) are not included in the coverage analysis with Ganache and Hardhat,
  • code coverage introduces a significant overhead in the execution time of the tests.

By enabling the coverage collection, a woke-coverage.cov file is generated in the current directory. To analyze this file, install Tools for Solidity, a VS Code extension that can be used to visualize the coverage of Solidity contracts directly in the editor. With the extension installed, execute the Tools for Solidity: Show Coverage command to open the coverage report.

Code coverage in VS Code

The coverage report is updated automatically when the woke-coverage.cov file is modified. To hide the coverage report, execute the Tools for Solidity: Hide Coverage command.


Contents of Solidity source files must not be modified since the last generation of pytypes, otherwise the coverage highlighting may be rendered incorrectly.