擅长:python、mysql、java
<p>您可以使用自定义装饰器,如:</p>
<pre><code>def skipIfAppVersionIsLowerThan(expected_version):
if StrictVersion(app_version) < StrictVersion(expected_version):
return unittest.skip(f'App version is lower than {expected_version}')
return lambda func: func
</code></pre>
<p>然后:</p>
<ol>
<li>单独测试或</li>
<li>把1.5.5测试放在一个单独的测试用例中,装饰整个班级</li>
</ol>
<p>示例:</p>
<pre><code>@skipIfAppVersionIsLowerThan('1.5.5')
def test1(self):
pass
</code></pre>
<hr/>
<p>“跳过测试”文档:<a href="https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failures" rel="nofollow noreferrer">https://docs.python.org/3/library/unittest.html#skipping-tests-and-expected-failures</a></p>