pdb
,在代码中插入import pdb; pdb.set_trace()
设置断点,运行脚本后可通过n
(下一步)、s
(进入函数)、c
(继续)等命令调试。ipdb
(pip install ipdb
),基于IPython提供更友好的交互式调试体验,用法与pdb
类似。logging
模块输出调试信息,可在代码中添加logging.debug('信息')
,运行后查看日志文件。unittest.TestCase
的测试类,使用assertEqual
等断言方法,运行python3 -m unittest test_file.py
。test_
开头),支持参数化测试,运行pytest tests/
自动发现并执行测试。pdb
或ipdb
快速调试。pytest
,搭配虚拟环境管理依赖。