我正在寻找一种在PyTest中运行所有单元测试的方法,即使其中一些测试失败了.我知道必须有一个简单的方法来做到这一点.我检查了CLi选项,并通过这个网站查找类似的问题/答案,但没有看到任何东西.对不起,如果已经回答了这个问题.
例如,请考虑以下代码片段,其中包含PyTest代码:
def parrot(i):
return i
def test_parrot():
assert parrot(0) == 0
assert parrot(1) == 1
assert parrot(2) == 1
assert parrot(2) == 2
Run Code Online (Sandbox Code Playgroud)
默认情况下,执行在第一次失败时停止:
$ python -m pytest fail_me.py
=================== test session starts ===================
platform linux2 -- Python 2.7.10, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /home/npsrt/Documents/repo/codewars, inifile:
collected 1 items
fail_me.py F
=================== FAILURES ===================
___________________ test_parrot ___________________
def test_parrot():
assert parrot(0) == 0
assert parrot(1) == 1
> assert parrot(2) == 1
E assert 2 == 1
E + where …Run Code Online (Sandbox Code Playgroud) 我有以下bash脚本:
#!/bin/sh
num_loops=3
for i in `seq $num_loops`:
do
printf 'Iteration %s\n' $i
done
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我得到以下输出.
$ ./loop-test.sh
Iteration 1
Iteration 2
Iteration 3:
Run Code Online (Sandbox Code Playgroud)
我想知道为什么脚本在最后一次迭代结束时生成一个无关的冒号(":")?我知道变量'i'是一个字符串,但为什么'seq'命令中的最后一次迭代会附加冒号?