Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种干净的方法来测试 Hamcrest (python) 中的列表是否为空。通过检查列表长度等有几种方法可以做到这一点,但我想要一些读起来很好的测试。
使用empty匹配器:
empty
assert_that(mylist, is_not(empty()))
我assertNotEqual([], list)用来检查列表是否为空
assertNotEqual([], list)
具有最佳可读性的最干净的方式可能是这样的:
from hamcrest import assert_that, is_, empty, not_ assert_that([], is_(not_(empty())))