python
runtime_error
ai_generated
true
Failed: DID NOT RAISE <class 'SystemExit'> UNEXPECTED EXCEPTION: SystemExit(0)
ID: python/pytest-doctest-capture-stdout
80%Fix Rate
83%Confidence
0Evidence
2024-12-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
A doctest that calls sys.exit() or argparse with --help exits the interpreter; doctest expects a return value, not a process exit.
generic中文
调用 sys.exit() 或带 --help 的 argparse 的 doctest 退出了解释器;doctest 期望返回值,而不是进程退出。
Workarounds
-
90% success
>>> import sys >>> try: ... main(["--help"]) ... except SystemExit as e: ... print("exit", e.code) exit 0 -
95% success
def main(argv=None) -> int: ... return 0 if __name__ == "__main__": raise SystemExit(main())
Dead Ends
Common approaches that don't work:
-
85% fail
Continues after failure but doesn't prevent SystemExit.
-
70% fail
In doctest source, suppress changes the observable output.
-
80% fail
Hides a real usability bug in the CLI.