You set a feature flag to false, but the code enables it. In Python, bool() tests the value of an object; it does not interpret an English boolean label. A nonempty string such as "false" or "0" is true. An empty string is false. See Python’s truth-value rules.
Environment variable values are strings, as described in the os documentation. This article tests synthetic dictionaries with those shapes. It never reads your environment, secrets, or .env files.
Decide the policy before choosing a default
An optional-feature fixture accepted only exact lowercase true and false; absence disabled that feature. Ten synthetic cases passed on Python 3.14.3. The fixture rejected empty strings, 0, mixed case, surrounding spaces, yes, and nonstrings. That vocabulary is an application policy, not a Python requirement.
Do not transfer the optional-feature default to a protective flag. For DRY_RUN, a missing value that disables dry-run mode could allow a real change. The following demonstration instead defaults missing input to preview mode and rejects a present but empty value.

Concept diagram of the synthetic example, not terminal output or Python’s accepted-value specification.
| Synthetic DRY_RUN input | Policy in this example |
|---|---|
| Missing | Preview only |
true | Preview only |
false | Permit the simulated action |
| Empty or any other value | Reject before the action |
A required flag could instead reject absence. Choose and document that policy for your application. If accepting TRUE, yes, or whitespace is intentional, enumerate and test those choices. Do not silently expand the accepted values while debugging.
Run a harmless action-boundary test
Save the following complete script as dry_run_demo.py. It only appends a marker to an in-memory list. It cannot delete files, send requests, or change settings. It is not a production execution wrapper.
"""Synthetic mappings only. The simulated action appends to a list."""
import sys
def dry_run(settings):
if 'DRY_RUN' not in settings:
return True # Deliberate protective default for this application.
raw = settings['DRY_RUN']
if raw == 'true':
return True
if raw == 'false':
return False
raise ValueError('DRY_RUN must be exactly true or false')
def run(settings, actions):
preview = dry_run(settings) # Validate before any action.
if preview:
return 'preview only'
actions.append('simulated change')
return 'simulated change recorded'
if __name__ == '__main__':
examples = {'missing': {}, 'empty': {'DRY_RUN': ''},
'true': {'DRY_RUN': 'true'}, 'false': {'DRY_RUN': 'false'},
'typo': {'DRY_RUN': 'flase'}}
actions = []
try:
result = run(examples[sys.argv[1]], actions)
except (ValueError, KeyError, IndexError):
print('configuration rejected; actions=0', file=sys.stderr)
raise SystemExit(2)
print(f'{result}; actions={len(actions)}')
Run python3 dry_run_demo.py typo. The result is printed to stderr:
configuration rejected; actions=0
The process exits with status 2. python3 dry_run_demo.py false exits 0 and prints simulated change recorded; actions=1. The action is only a list marker, never a real operation.
We executed missing, empty, true, false, and typo inputs as separate Python processes. Missing and true produced preview output with zero actions; empty and typo exited 2 with zero actions; false produced one simulated action. These five cases test the execution boundary separately from the ten parsing cases.
Keep invalid configuration on the failure path
The parse happens before the action. Do not catch a configuration error and continue with DRY_RUN=False. Do not replace missing and empty values with the same fallback through value or default: those inputs may need different handling. Never infer the intended value of a misspelling.
For a tool you maintain, find the point where configuration becomes a boolean. Write down the accepted strings, the missing-value default, and whether an empty value is an error. Test a typo with an inert substitute for the real action, then confirm that the error path cannot reach that action. A dry-run flag is not a substitute for permissions, transactions, or other safeguards.
This differs from JSON duplicate-key detection: no object member is being overwritten here. It also differs from an MCP environment inheritance problem: a value may arrive correctly and still be interpreted incorrectly.
Limits of this test
We tested Python 3.14.3 locally; the linked documentation is for the 3.14 series. We did not test shell export syntax, dotenv loaders, IDEs, live CI, Windows, or any third-party product’s configuration rules. No production environment was inspected. The boolean names and defaults shown here are deliberately narrow and do not define a universal parser.
No paid product is required. The useful reader action is to reproduce the typo case and audit one configuration-to-action boundary in their own tool. A page view or documentation click would not prove they did that successfully.