CmdMox follows a strict record → replay → verify lifecycle. First declare expectations, then run your code with the shims active, finally verify that interactions matched what was recorded.
The three phases are defined in the design document:
- Record – describe each expected command call, including its arguments and behaviour.
- Replay – run the code under test while CmdMox intercepts command executions.
- Verify – ensure every expectation was met and nothing unexpected happened.
These phases form a strict sequence for reliable command-line tests.
A typical test brings the three phases together:
cmd_mox.mock("git").with_args("clone", "repo").returns(exit_code=0)
my_tool.clone_repo("repo")
# Replay begins automatically before the test function executes; verification runs during teardown.