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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:42:39+00:00 2026-06-18T14:42:39+00:00

I am doing some unittests with python and some pre-test checks in setUpClass .

  • 0

I am doing some unittests with python and some pre-test checks in setUpClass. How can I throw a unitest–fail within the setUpClass, as the following simple example:

class MyTests(unittest.TestCase):

    @classmethod
    def setUpClass(cls):    
        unittest.TestCase.fail("Test")

    def test1(self):
        pass

if __name__ == '__main__':
    unittest.main()

gives the error TypeError: unbound method fail() must be called with TestCase instance as first argument (got str instance instead).

I understand the error I get as fail is a instance method, and I don’t have an instance of MyClass yet. Using an instance on-the-fly like

unittest.TestCase().fail("Test")

also does not work, as unittest.TestCase itself has no tests. Any ideas how to fail all tests in MyClass, when some condition in setUpClass is not met?

Followup question: Is there a way to see the tests in setUpClass?

  • 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-18T14:42:40+00:00Added an answer on June 18, 2026 at 2:42 pm

    self.fail("test") put into your setUp instance method fails all the tests

    I think the easiest way to do this at the class level is to make a class variable so something like:

    @classmethod
    def setUpClass(cls):
       cls.flag = False
    
    def setUp(self):
       if self.flag:
           self.fail("conditions not met")
    

    Hope this is what you want.

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

Sidebar

Related Questions

I'm doing some Unit/Integration testing in a Non-Java language (Python), using a test-framework (
I am doing some R&D on selenium+python. I wrote some test cases in python
While doing some JavaScript performance tests I came up with the following piece of
While doing some random experimentation with a factorial program in C, Python and Scheme.
I'm doing some simple MS unit tests on my standard, nothing special controller. When
I have a life-cycle problem doing some test suite with JUnit. In order to
I'm doing some unit tests for an EntityEventListener from NHibernate, and I'm got stuck
I'm doing a ASP.Net MVC2 project and i want to do some unit tests
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read

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.