<p>我正在使用<code>unittest</code>框架用python2.6编写一个测试套件,我想在代码中使用断言。我知道asserts得到了彻底的改进,并且在2.7+中更好,但是我现在只能使用2.6。在</p>
<p>我在使用断言时遇到问题。我希望能够使用<code>assertIn(a,b)</code>特性,但是遗憾的是,这只在2.7+中使用。所以我意识到我必须使用<code>assertTrue(x)</code>,这也是2.6版本中的,但那没用。然后,我查看了<a href="http://docs.python.org/library/unittest.html#deprecated-aliases" rel="nofollow">this document</a>,在以前的版本中,<code>assertTrue(x)</code>曾经是{<cd5>},所以我在代码中使用了它,但仍然没有结果。在</p>
<p>我得到的信息是:</p>
<blockquote>
<p>NameError: global name 'failUnless' is not defined</p>
</blockquote>
<p>这和我为<code>assertIn(a,b)</code>和{<cd3>}得到的结果是一样的。
所以我完全不知道该怎么做。在</p>
<p>我的简短版本:</p>
<p>我希望能够在Python2.6中实现<code>assertIn(a,b)</code>。
有人能解决这个问题吗?在</p>
<p>我的代码:</p>
<pre><code>import unittest
class test_base(unittest.TestCase):
# some functions that are used by many tests
class test_01(test_base):
def setUp(self):
#set up code
def tearDown(self):
#tear down code
def test_01001_something(self):
#gets a return value of a function
ret = do_something()
#here i want to check if foo is in ret
failUnless("foo" in ret)
</code></pre>
<p><strong>编辑</strong>:看来我是个白痴。我只需要添加<code>self.assert....</code>就可以了。在</p>