在python中使用什么函数进行输出_在Python中,测试函数的标准输出

我一直在尝试编写一个测试(使用unittest)来测试函数的输出。

函数如下:def main():

arg_pressent = len(sys.argv)

if arg_pressent < 2:

print "usage: ./pyPeerChat [IP ADDRESS of pc] / [0 (if the network is not known. This will assume that this peer will be the start of a new network)]"

else:

IP = str(sys.argv[1])

connect.main(IP)

if __name__ == '__main__':

main()

所以,我的测试需要测试这样一个事实:当这个函数独立运行时(没有传递任何参数),它会打印出用法:./pyPeerChat[IP ADDRESS of pc]/[0(如果网络未知)。这将假定这个对等端将是一个新网络的开始。在

到目前为止,我正在尝试实施的测试是:

^{pr2}$

然而,我一直没能成功地通过这次考试。测试失败了,我得到了一个错误。以下是测试的整个输出,错误如下:======================================================================

ERROR: test_main_prints_without_ARGs (__main__.TestMain)

----------------------------------------------------------------------

Traceback (most recent call last):

File "testpyPeerChat.py", line 24, in test_main_prints_without_ARGs

pyPeerChat.main()

File "/home/peer-node/Testing/P2PChat/source/pyPeerChat.py", line 47, in main

print "usage: ./pyPeerChat [IP ADDRESS of Bootpeer] / [0 (if the network is not known. This will assume that this peer will be the start of a new network)]"

TypeError: unicode argument expected, got 'str'

----------------------------------------------------------------------

Ran 1 test in 0.000s

FAILED (errors=1)

我完全不确定这个错误意味着什么,因为代码运行良好。有没有更简单的方法来编写我需要的测试,或者修复我的测试?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值