Install
Use Python 3.10 or later and install niltest into the virtual environment that will run it. Command names differ by operating system and Python installation.
Windows commonly uses python -m pip, while Ubuntu and macOS commonly use python3 -m pip. After activation, a virtual environment usually exposes its interpreter as python and its installer as pip on every OS.
pip install and pip3 install may also work. Using python -m pip or python3 -m pip is safer because it explicitly selects the Python receiving the package.
pip install niltest Installs into the active virtual environment.
Declare a case
given contains real keyword arguments and returns describes the expected result. Use names that explain the behavior to another developer.
import niltest
from niltest import Mode, expect, scenario
niltest.configure(mode=Mode.TEST) # @scenarioより前
@scenario("配送料")
def shipping_fee(subtotal: int, premium: bool = False) -> int:
if expect:
expect.case(
"プレミアム会員は無料",
given={"subtotal": 1_000, "premium": True},
returns=0,
)
return 0 if premium or subtotal >= 5_000 else 500Run from the CLI
Pass the import path of the module that defines your scenarios. A successful run exits with code 0.
niltest run your_package.specs --language jaWhere to go next
- Return fixed values while developing → Mocking
- Check types or dynamic conditions → Expectations
- Add niltest to CI → Running checks