Note that there are some explanatory texts on larger screens.

plurals
  1. POpython 2.6. unittest framework, asserts: help required
    primarykey
    data
    text
    <p>I am writing a test suite in python 2.6 using the <code>unittest</code> framework, and I want to use asserts in my code. I know that asserts got a complete overhaul and are much nicer in 2.7+ but I am confined to using 2.6 for now.</p> <p>I am having problems using asserts. I want to be able to use the <code>assertIn(a,b)</code> feature, but alas, that is only in 2.7+. So I realized I must use the <code>assertTrue(x)</code> which is also in 2.6, but that didn't work. Then, I looked at <a href="http://docs.python.org/library/unittest.html#deprecated-aliases" rel="nofollow">this document</a> which says that in previous versions <code>assertTrue(x)</code> used to be <code>failUnless(x)</code>, so I used that in my code, and still no results.</p> <p>I get the message: </p> <blockquote> <p>NameError: global name 'failUnless' is not defined</p> </blockquote> <p>which is the same thing I got for <code>assertIn(a,b)</code> and for <code>assertTrue(x)</code>. So I am totally at a loss for what I should do.</p> <p>shorter version of my problem:</p> <p>I want to be able to implement <code>assertIn(a,b)</code> in python 2.6. Anyone have any solutions to this?</p> <p>my code:</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>edit</strong>: Seems I am an idiot. All I needed to do was add <code>self.assert....</code> and it worked.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload