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

  • SEARCH
  • Home
  • 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 344471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:59:37+00:00 2026-05-12T10:59:37+00:00

I want to overload failUnlessEqual in unittest.TestCase so I created a new TestCase class:

  • 0

I want to overload failUnlessEqual in unittest.TestCase so I created a new TestCase class:

import unittest

class MyTestCase(unittest.TestCase):
    def failUnlessEqual(self, first, second, msg=None):
        if msg:
            msg += ' Expected: %r - Received %r' % (first, second)
        unittest.TestCase.failUnlessEqual(self, first, second, msg)

And I am using it like:

class test_MyTest(MyTestCase):
    def testi(self):
        i = 1
        self.assertEqual(i, 2, 'Checking value of i')
    def testx(self):
        x = 1
        self.assertEqual(x, 2, 'Checking value of i')

This is what I get when I run the tests

>>> unittest.main()
FF
======================================================================
FAIL: testi (__main__.test_MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<stdin>", line 4, in testi
AssertionError: Checking value of i

======================================================================
FAIL: testx (__main__.test_MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<stdin>", line 7, in testx
AssertionError: Checking value of x

----------------------------------------------------------------------
Ran 2 tests in 0.000s

FAILED (failures=2)

I was expecting that the the message would be ‘Checking value of x Expecting: 2 – Received: 1’

MyTestCase class is not being used at all.
Can you tell me what I am doing wrong?

  • 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-05-12T10:59:38+00:00Added an answer on May 12, 2026 at 10:59 am

    You are calling assertEqual, but define failUnlessEqual. So why would you expect that your method is called – you are calling a different method, after all?

    Perhaps you have looked at the definition of TestCase, and seen the line

    assertEqual = assertEquals = failUnlessEqual
    

    This means that the method assertEqual has the same definition as failUnlessEqual. Unfortunately, that does not mean that overriding failUnlessEqual will also override assertEqual – assertEqual remains an alias for the failUnlessEqual definition in the base class.

    To make it work correctly, you need to repeat the assignments in your subclass, thereby redefining all three names.

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

Sidebar

Related Questions

I want to overload new operator in a template class. But something wrong happends.
I have a Card class and I want to overload the > operator to
I have a smart pointer class and I want to overload operator-> ; it's
I'm writing a collection class. I want to overload the square brackets operator ([])
I created my own Dictionary class, based on the .NET Dictionary. Now I want
So I making a container class for integers and I want to overload the
I want to overload the operator + in a class which has a vector
I have a simple class for which I want to overload operator as below
I have a class that uses a struct, and I want to overload the
I want to overload the >> operator in c++ so that my class of

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.