宁夏住房和建设厅网站,哈尔滨城乡建设网站,公司网站服务器优化,设计头条官网import pytest
def test_good():for i in range(1000):print(i)def test_bad():print(this should fail!)assert False比如上述程序#xff0c;运行之后只能看到输出了’this should fail!#xff1b;但是debug版的测试运行后又能看到test_good函数中的输出。 这是为什么呢this should fail!)assert False比如上述程序运行之后只能看到输出了’this should fail!但是debug版的测试运行后又能看到test_good函数中的输出。 这是为什么呢
pytest自动会capture通过的那些测试用例运行中所print出来的output而failed的那些测试用例则会打印其中运行过的print的输出。如果想要获取全部的输出 在终端中运行下面其中一行即可 这两种都可以
pytest name.py --captureno # show print statements in consolepytest name.py -s # equivalent to previous command