Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:33:42+00:00 2026-06-09T14:33:42+00:00

I am writing a test suite in python 2.6 using the unittest framework, and

  • 0

I am writing a test suite in python 2.6 using the unittest 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.

I am having problems using asserts. I want to be able to use the assertIn(a,b) feature, but alas, that is only in 2.7+. So I realized I must use the assertTrue(x) which is also in 2.6, but that didn’t work. Then, I looked at this document which says that in previous versions assertTrue(x) used to be failUnless(x), so I used that in my code, and still no results.

I get the message:

NameError: global name ‘failUnless’ is not defined

which is the same thing I got for assertIn(a,b) and for assertTrue(x).
So I am totally at a loss for what I should do.

shorter version of my problem:

I want to be able to implement assertIn(a,b) in python 2.6.
Anyone have any solutions to this?

my 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)

edit: Seems I am an idiot. All I needed to do was add self.assert.... and it worked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:33:44+00:00Added an answer on June 9, 2026 at 2:33 pm
    import unittest
    
    class MyTest(unittest.TestCase):
        def test_example(self):
            self.assertTrue(x)
    

    This should work, based on the docs for unittest from Python 2.6. Be sure to use it as TestCase.assertTrue().

    edit: In your example, set it as self.failUnless("foo" in ret) and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use nose to test an application that I am writing using
I'm writing test code that needs to clean up the entities it creates when
What are the current rules for writing python code that will pass cleanly through
I'm writing some kind of automated test suite and I want to make sure
I'm writing a test suite for Django that runs tests in a tree-like fashion.
I'm writing a selenium grid test suite which is going to be run on
I am writing code to performance test a web site. I have the following
I writing test cases for Android apps using Robotium. One of my test cases
In writing Test case as I know, first step/task is to identify the Test
We want to design a simple domain specific language for writing test scripts to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.