相关疑难解决方法(0)

Python CLI程序单元测试

我正在开发一个python命令行界面程序,我在测试时发现它很无聊,例如,这里是程序的帮助信息:

usage: pyconv [-h] [-f ENCODING] [-t ENCODING] [-o file_path] file_path

Convert text file from one encoding to another.

positional arguments:
  file_path

optional arguments:
  -h, --help            show this help message and exit
  -f ENCODING, --from ENCODING
                        Encoding of source file
  -t ENCODING, --to ENCODING
                        Encoding you want
  -o file_path, --output file_path
                        Output file path
Run Code Online (Sandbox Code Playgroud)

当我对程序进行更改并想要测试某些内容时,我必须打开一个终端,输入命令(带有选项和参数),输入enter,然后查看运行时是否发生任何错误.如果确实发生了错误,我必须回到编辑器并从头到尾检查代码,猜测bug的位置,进行小的更改,写print行,返回终端,再次运行命令......

递归.

所以我的问题是,使用CLI程序进行测试的最佳方法是什么,它可以像使用普通python脚本进行单元测试一样简单吗?

python testing unit-testing command-line-interface

20
推荐指数
4
解决办法
7545
查看次数