【发布时间】:2016-04-13 17:30:30
【问题描述】:
我想在我的 Python 单元测试中显示我一直懒惰和停用测试的标志位置。
但我也有条件执行,它们不是懒惰的,它们是由测试时的性能或系统条件驱动的。这些是 skipUnless 的,我想完全忽略它们。
让我们使用一些 cmets 放入文件 test_so_bashregex.txt 中的一些输入。
!ignore this, because skipUnless means I have an acceptable conditional flag
@unittest.skipUnless(do_test, do_test_msg)
def test_conditional_function():
xxx
!catch these 2, lazy test-passing
@unittest.skip("fb212.test_urls_security_usergroup Test_Detail.test_related fails with 302")
def sometest_function():
xxx
@unittest.expectedFailure
def test_another_function():
xxx
!bonus points... ignore things that are commented out
# @unittest.expectedFailure
此外,我不能在管道中使用grep -v skipUnless,因为我真的想使用egrep -A 3 xxx *.py 来提供一些上下文,例如:
grep -A 3 "@unittest\." *.py
test_backend_security_meta.py: @unittest.skip("rewrite - data can be legitimately missing")
test_backend_security_meta.py- def test_storage(self):
test_backend_security_meta.py- with getMultiDb() as mdb:
test_backend_security_meta.py-
我尝试过的:
正在尝试@https://www.debuggex.com/
我尝试了@unittest\.(.+)(?!(Unless\()),但没有成功,因为它与前 3 个匹配。
同上@unittest\.[a-zA-Z]+(?!(Unless\())
@unittest\.skip(?!(Unless\()) 部分工作,在 2 上跳过。
尽管存在 Unless,但所有这些都进行了部分匹配。
在 bash egrep 上,这将结束,事情看起来并没有好多少。
jluc@explore$ egrep '@unittest\..*(?!(Unless))' test_so_bashregex.txt
egrep:重复运算符操作数无效
【问题讨论】:
标签: regex bash regex-negation