Plugin reference¶
CLI options¶
All options belong to the cocotb option group.
Flag |
Default |
Description |
|---|---|---|
|
|
Simulator name |
|
|
HDL top-level module name |
|
|
HDL library name |
|
|
HDL source files (repeatable) |
|
None |
Path to |
|
|
Include directories (repeatable) |
|
|
Preprocessor defines as name/value pairs (repeatable) |
|
|
Extra build arguments, shlex-split (repeatable) |
|
|
HDL parameters as name/value pairs (repeatable); passed to |
|
|
Enable waveform capture |
|
|
Force clean rebuild |
|
|
Base output directory |
|
|
Create a timestamped subdirectory for this run (useful for regression tracking) |
|
|
Environment modules to load before simulation (repeatable; see HPC support) |
Fixtures¶
testrun_uid(session)Timestamp string (
YYYYMMDD_HHMMSS) identifying this pytest invocation.sim_build_dir(session)Pathto the base output directory for this run. When--regressis passed this is<sim-build>/<testrun_uid>/; otherwise it is simply<sim-build>/.build_dir(session)Pathto the compiled HDL directory. Defaults to<sim_build_dir>/build/. When--wavesis enabled a separatebuild_waves/directory is used instead, so that wave-enabled and non-wave builds do not clobber each other.runner(session)The cocotb runner instance. Compiles the HDL design once per session using
cocotb_tools.runner.get_runner(). When pytest output capture is active, build output is redirected tobuild_dir/build.log.test_session(function)A
TestSessionbound to a unique per-test directory.
TestSession API¶
@dataclass
class TestSession:
runner: object
directory: Path
hdl_toplevel: str
test_module: str
waves: bool = False
log_file: Path | None = None
run(**kwargs) -> Path
Delegates to runner.test() with sensible defaults derived from the
dataclass fields. Any keyword argument accepted by runner.test() can be
passed to override the defaults (e.g. test_module, waves).
run() may only be called once per TestSession instance; a second
call raises RuntimeError.
When pytest output capture is active (the default), the log_file field is
automatically set to <test_dir>/sim.log so that simulator output is
captured to a file instead of being printed to stdout.
- class pytest_cocotb.session.TestSession(runner: object, directory: pathlib.Path, hdl_toplevel: str, test_module: str, waves: bool = False, log_file: pathlib.Path | None = None, hdl_toplevel_lang: str | None = None, verbose: bool = False, gui: bool = False, test_args: list[str] = <factory>, plusargs: list[str] = <factory>, extra_env: dict[str, str] = <factory>, seed: str | int | None = None, testcase: str | None = None, test_filter: str | None = None, results_xml: str | None = None, _has_run: bool = False)¶
Build behaviour¶
The
runnerfixture compiles HDL once at session scope.Subsequent tests reuse the compiled build in
build_dir.When
--wavesis enabled the build is placed inbuild_waves/instead ofbuild/, so you can switch between wave and non-wave runs without forcing a rebuild.Pass
--cleanto force a full rebuild.
Output directory layout¶
Without ``–regress`` (default):
sim_build/
├── build/ # compiled HDL (build_dir)
├── test_counter__test_counter_basic/
│ ├── sim.log # simulator stdout
│ └── ... # simulator output
└── ...
With ``–regress``:
sim_build/
└── 20250101_120000/ # testrun_uid
├── build/ # compiled HDL (build_dir)
├── test_counter__test_counter_basic/
│ ├── sim.log
│ └── ...
└── ...