Python API
Mode is the recommended public API. String modes such as configure(mode="test") remain available for existing code and concise configuration.
import niltest
from niltest import Mode
niltest.configure(mode=Mode.TEST) # @scenarioより前
from your_package.shipping import shipping_fee
result = niltest.run_tests(shipping_fee)
assert result.success
print(result.to_dict())Integrate with pytest
With pytest --niltest, every specification case becomes an independent pytest item and participates in normal reporting, exit codes, JUnit XML, and coverage.
Without --niltest, the plugin neither changes modes nor imports modules. Declare targets with repeatable --niltest-module options or pytest configuration.
pytest --niltest --niltest-module=your_package.specs
pytest --niltest --junitxml=report.xml --cov=your_package
# pyproject.toml
[tool.pytest.ini_options]
niltest_modules = ["your_package.specs"]CLI
Choose human-readable output or machine-readable JSON. Only scenarios registered by the requested modules are run.
niltest run your_package.specs
niltest run your_package.specs --jsonInspect a module as an architecture map
The inspect command lists signatures, input and output types, cases, mockability, and input diagnostics as text or JSON.
Markdown includes a case table, expectations, and source locations for direct use in reviews. The existing --json flag remains a compatibility alias.
Replace your_package.services with an importable target-module path. Inspect imports that module but does not execute its specification cases.
niltest inspect your_package.services # terminal
niltest inspect your_package.services --format json # CI / tools
niltest inspect your_package.services --format markdown # review docsExit codes
- 0: every specification passed
- 1: one or more specifications failed
- 2: invalid arguments, imports, or target modules