Python Test Runners

Say goodbye to Makefiles. Use pure Python scripts (via `cocotb-test` or `cocotb.runner`) to configure and launch your simulations.

Why use a Runner?

Makefiles are great, but Python is better. Using a Python runner allows you to:

  • Parametrize tests easily (loop through configurations).
  • Use `pytest` for parallel execution (`pytest -n auto`).
  • Keep verification logic and build logic in the same language.

Example: `test_runner.py`

from cocotb_test.simulator import run
import pytest
@pytest.mark.parametrize("width", [8, 16, 32])
def test_adder(width):
    run(
        verilog_sources=["adder.sv"],
        toplevel="adder",            # Name of Verilog module
        module="test_adder",         # Name of Python test file
        parameters={"WIDTH": str(width)},
        sim_build=f"sim_build/run_{width}"
    )

Run this with a simple command: pytest test_runner.py.

Bonus: Traditional Makefile Snippet

If you prefer the traditional Cocotb flow, here is a clean `Makefile` template:

SIM ?= icarus
TOPLEVEL_LANG ?= verilog
VERILOG_SOURCES += $(PWD)/my_design.sv
TOPLEVEL = my_design
MODULE = my_test
include $(shell cocotb-config --makefiles)/Makefile.sim