以bdd方式测试任何命令行接口。

bddcli的Python项目详细描述


bddcli

以bdd方式测试任何命令行接口。

PyPIBuild StatusCoverage Status

关于

在另一个(独立的)框架中轻松测试命令行接口的框架 处理并收集进程的stdout、stderr和returnstatus。

安装

只支持Python >= 3.6

pip install bddcli

快速启动

参数

importsysfrombddcliimportGiven,when,stdout,status,stderr,Application,givendeffoo():print(' '.join(sys.argv))return0app=Application('foo','mymodule:foo')withGiven(app,'Pass single positional argument','bar'):assertstatus==0assertstdout=='foo bar\n'when('Without any argument',given-'bar')assertstdout=='foo\n'when('Pass multiple arguments','bar baz')assertstdout=='foo bar baz\n'when('Pass multiple arguments, another method',['bar','baz'])assertstdout=='foo bar baz\n'when('Add an argument',given+'baz')assertstdout=='foo bar baz\n'

标准输入

withGiven(app,'Pass stdin',stdin='foo'):assert...when('stdin is empty',stdin='')assert...

标准输出和误差

frombddcliimportstderr,stdoutassertstderr==...assertstdout==...

环境变量

importosfrombddcliimportGiven,stdout,Application,when,givendeffoo():e=os.environ.copy()dele['PWD']print(' '.join(f'{k}: {v}'fork,vine.items()))app=Application('foo','mymodule:foo')withGiven(app,'Environment variables',environ={'bar':'baz'}):assertstdout=='bar: baz\n'when('Without any variable',environ=given-'bar')assertstdout=='\n'when('Add another variables',environ=given+{'qux':'quux'})assertstdout=='bar: baz qux: quux\n'

有关更多示例,请参见测试

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在Java中使用工厂设计模式   解析服务器安全性的java最佳实践   java如何解决由于某种原因导致的执行失败?   关于Servlet的java   如何在java中生成一个大的(30MB+)xml文件?   匿名类重写与传递接口,用于在Java中设计回调   java jar从运行时开始。getRuntime()。exec()比从命令行运行的时间长   java Ant脚本排除文件夹(某些文件除外)   java在Windows 10计算机上运行时遇到Maven错误   java Hibernate在同一个表中级联   java PayPal API设置返回URL   java如何在选项卡的右侧显示关闭按钮   当按下Jmenu按钮时,使用java操作侦听器退出程序