pyoz test¶
Build the module and run embedded inline tests.
Usage¶
Options¶
| Option | Description |
|---|---|
-v, --verbose |
Show individual test names and results |
-r, --release |
Build in release mode before testing |
-h, --help |
Show help message |
How It Works¶
- Builds the module (debug mode by default, release with
-r) - Extracts the embedded test file from the compiled
.so - Validates Python syntax with
py_compile - Runs
python3 -m unitteston the extracted file
Tests are defined inline in your Zig module using pyoz.@"test"() and pyoz.testRaises(). See the Testing Guide for details on writing tests.
Output¶
Building mymodule v0.1.0 (Debug)...
Python 3.10 detected
Module: src/lib.zig
Using build.zig
Running tests...
....
----------------------------------------------------------------------
Ran 4 tests in 0.001s
OK
With --verbose:
Running tests...
test_add_handles_negatives (zig-out.lib.__pyoz_test.TestMymodule) ... ok
test_add_returns_correct_result (zig-out.lib.__pyoz_test.TestMymodule) ... ok
test_divide_by_zero_raises_valueerror (zig-out.lib.__pyoz_test.TestMymodule) ... ok
test_point_magnitude (zig-out.lib.__pyoz_test.TestMymodule) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.001s
OK
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | All tests passed |
| 1 | One or more tests failed, syntax error in test code, or no tests found |
No Tests Defined¶
If your module doesn't have a .tests field:
pyoz bench¶
Build the module in release mode and run embedded benchmarks.
Usage¶
Options¶
| Option | Description |
|---|---|
-h, --help |
Show help message |
How It Works¶
- Builds the module in release mode (always, for accurate timing)
- Extracts the embedded benchmark file from the compiled
.so - Validates Python syntax with
py_compile - Runs the benchmark script with
python3
Each benchmark is timed over 100,000 iterations using Python's timeit module.
Benchmarks are defined inline in your Zig module using pyoz.bench(). See the Testing Guide for details.
Output¶
Building mymodule v0.1.0 (Release)...
Python 3.10 detected
Module: src/lib.zig
Using build.zig
Running benchmarks...
Benchmark Results:
------------------------------------------------------------
add performance 20,051,810 ops/s
multiply performance 20,268,969 ops/s
------------------------------------------------------------
Exit Codes¶
| Code | Meaning |
|---|---|
| 0 | Benchmarks completed |
| 1 | Syntax error in benchmark code, build failure, or no benchmarks found |
No Benchmarks Defined¶
If your module doesn't have a .benchmarks field: