🕵️♀️ CmdMox – Python-native command mocking so you never have to write another shell test again
Replace your flaky bats tests, your brittle log-parsing hacks, and that one Bash script that only works on Tuesdays. CmdMox intercepts external commands with Python shims, speaks fluent IPC over Unix domain sockets and Windows named pipes, and enforces your expectations like a disappointed parent.
- Mocks? Verified.
- Stubs? Quietly compliant.
- Spies? Judging everything you do.
Designed for pytest, built for people who’ve seen things—like ksh93 unit test
harnesses and AIX cronjobs running sccs.
If you've ever mocked curl with cat, this library is your penance.
For detailed instructions, see docs/usage-guide.md.
Platform support: Linux, macOS, and Windows. CmdMox emits POSIX symlink
shims on Unix-like systems and .cmd launchers backed by named pipes on
Windows, so the same tests and fixtures run across all three platforms.
✅ Requirements
- Python 3.11 or newer (to leverage modern enum.StrEnum support)
🧪 Example: Testing a command-line script with CmdMox
Let’s say your script under test calls git clone and curl. You want to test
it without actually cloning anything because you value your bandwidth and
your sanity.
# test_my_script.py
def test_clone_and_fetch(cmd_mox):
# Define expectations (fixture auto-enters REPLAY before the test body)
cmd_mox.mock("git") \
.with_args("clone", "https://a.b/c.git") \
.returns(exit_code=0)
cmd_mox.mock("curl") \
.with_args("-s", "https://a.b/c/info.json") \
.returns(stdout='{"status":"ok"}')
# Code under test runs with mocked git and curl
result = my_tool.clone_and_fetch("https://a.b/c.git")
# Assert your code didn’t mess it up
assert result.status == "ok"
# Verification happens automatically during pytest teardown.
When it passes: your mocks were used exactly as expected.
When it fails: you'll get a surgically precise diff of what was expected vs what your misbehaving code actually did.
No subshells. No flaky greps. Just clean, high-fidelity, Pythonic command mocking.
🧯 Scope (and what’s gloriously out of it)
CmdMox is for mocking commands—not re-enacting bash(1) interpretive
dance theatre.
Out of scope (for now, or forever):
-
🧞 Shell function mocking – you want
eval, you wait a year. Or just don’t. -
🦕 Legacy UNIX support – AIX, Solaris, IRIX? Sorry boys, the boat sailed, caught fire, and sank in 2003.
-
🧩 Builtin mocking –
cd,exec,trap? No. Just no. -
🧪 Calling commands under test – use
subprocess,plumbum, or whatever black magic suits your taste. CmdMox doesn't care how you run them—as long as you run them like you mean it.
Release files for cmd-mox 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cmd_mox-0.2.0.tar.gz | 122.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cmd_mox-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 281.4 kB
Release files / cmd_mox-0.2.0.tar.gz
| Download URL | cmd_mox-0.2.0.tar.gz |
|---|---|
| Size | 122.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01d3764fd330b6b5ea28acb84e18f736a778c6298259aae3186656b658301985
|
|
BLAKE2b-256 checksum How to use checksums |
29a06c166408ec9a4cb1697cc22ca8f749f11a01a56027742c8abe8b50dc21c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|
Release files / cmd_mox-0.2.0-py3-none-any.whl
| Download URL | cmd_mox-0.2.0-py3-none-any.whl |
|---|---|
| Size | 159.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73da938977d556190d1246d9bde1e47da69aeefed7de557c7910984348b78bdc
|
|
BLAKE2b-256 checksum How to use checksums |
d87753a0297ab2e3e8c83ec20f4476525aff827a163bece9a73b74ef3da9ed2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|