擅长:python、mysql、java
<p>它运行了你所有的测试。您只编写了一个测试,并且该测试已运行</p>
<p>如果您想要非致命断言,如果断言失败,测试将继续进行(如Google test的EXPECT宏),请尝试提供该功能的<a href="http://pythontesting.net/pytest-expect/" rel="noreferrer">pytest-expect</a>。以下是他们网站给出的示例:</p>
<pre><code>def test_func(expect):
expect('a' == 'b')
expect(1 != 1)
a = 1
b = 2
expect(a == b, 'a:%s b:%s' % (a,b))
</code></pre>
<p>您可以看到,预期失败不会停止测试,所有失败的预期都会得到报告:</p>
<pre><code>$ python -m pytest test_expect.py
================ test session starts =================
platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.7.0
rootdir: /Users/okken/example, inifile:
plugins: expect
collected 1 items
test_expect.py F
====================== FAILURES ======================
_____________________ test_func ______________________
> expect('a' == 'b')
test_expect.py:2
--------
> expect(1 != 1)
test_expect.py:3
--------
> expect(a == b, 'a:%s b:%s' % (a,b))
a:1 b:2
test_expect.py:6
--------
Failed Expectations:3
============== 1 failed in 0.01 seconds ==============
</code></pre>