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 7062835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:38:30+00:00 2026-05-28T04:38:30+00:00

I have a unittest.TestCase child, which defines several domain specific assert Checks. I would

  • 0

I have a unittest.TestCase child, which defines several domain specific assert Checks.
I would like to run some unittests to unittest this functionality to control that everything work on future updates.

class MyBaseTestCase(unittest.TestCase):
    def setUp(self):
        ...
    def tearDown(self):
        ...
    def run(self, result):
        ...
    def assertSpec(self, condition, message):
        ...

I want to instantiate MyBaseTestCase in other unit test, like this:

class TestBase(unittest.TestCase):
    def test_assertSpec(self):
        self.testclass = MyBaseTestCase()
        self.assertRaises(AssertionError, self.testclass.assertSpec, False)

I’m encountering multiple different errors, when doing this, so my question is what is a common practice for unittesting custom unittest functions?

In case it helps:

$ jython
>>> import sys
>>> sys.version
'2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) \n[Java HotSpot(TM) Server VM (Sun Microsystems Inc.)]'
  • 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-28T04:38:31+00:00Added an answer on May 28, 2026 at 4:38 am

    Not sure if there’s anything Jython specific that would break this, but I would do something like this:

    import StringIO
    import unittest
    
    
    # The TestCase subclass to test    
    class MyBaseTestCase(unittest.TestCase):
        def assertSpec(self, thing):
            assert thing == 123
    
    
    # The testcase for MyBaseTestCase
    class TestMyTest(unittest.TestCase):
        def test_assetSpec(self):
            """Ensure assertSpec works
            """
    
            class _TestSpec(MyBaseTestCase):
                def test_failure_case(self):
                     self.assertSpec(121)
                def test_success_case(self):
                     self.assertSpec(123)
    
            # Load tests from _TestSpec
            loader = unittest.TestLoader()
            suite = loader.loadTestsFromTestCase(_TestSpec)
    
            # Create runner, and run _TestSpec
            io = StringIO.StringIO()
            runner = unittest.TextTestRunner(stream = io)
            results = runner.run(suite)
    
            # Should be one failed test, and one passed test
            self.assertEquals(results.testsRun, 2)
            self.assertEquals(len(results.failures), 1)
    
    if __name__ == "__main__":
        unittest.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a unittest.TestCase that looks like.. class test_appletrailer(unittest.TestCase): def setup(self): self.all_trailers =
If I have an assert in a unittest.TestCase as shown below: self.assertTrue( person.age ==
I have a test case: class LoginTestCase(unittest.TestCase): ... I'd like to use it in
Suppose I have a unittest like this class TestABC(unittest.TestCase): def setUp(self): .... def test001_abc(self):
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have the following django test case that is giving me errors: class MyTesting(unittest.TestCase):
I have some Twisted code which creates multiple chains of Deferreds. Some of these
I have a test case class like this one: import unittest import sys class
I have an underlying class which I want to place in some code. I
I have written a test case which shows the error from unittest import *

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.