Enable development modes before import
Python evaluates decorators when a module loads. Set NILTEST_MODE before importing the target module when using test or mock. The CLI selects test automatically before it imports modules.
# Python: importする前に設定
from niltest import Mode, configure
configure(mode=Mode.TEST)
# macOS / Linux
NILTEST_MODE=test python app.py
# Windows PowerShell
$env:NILTEST_MODE = "test"; python app.pyZero cost at function-call time
The existing if expect: API remains supported. To remove even that truth check, declare case() values outside the function with @docs.
Place @scenario outside @docs. In the default production mode, the original function is returned with no runtime wrapper and no niltest branch in its body.
from niltest import case, docs, scenario
@scenario("配送料")
@docs(case("プレミアム会員", given={"premium": True}, returns=0))
def shipping_fee(premium: bool) -> int:
return 0 if premium else 500The precise performance guarantee
In production mode, niltest creates no scenario wrapper and does not build expect.case argument dictionaries.
The explicit if expect: truth check remains. This is a predictable minimal path, not a claim of absolute zero cost.
Measure your target environment
python benchmark_production.py