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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:16:51+00:00 2026-06-16T16:16:51+00:00

I have unittest code like the following: import unittest class MyUnitTest(unittest.TestCase): def setUpClass(self): do_something_expensive_for_all_sets_of_tests()

  • 0

I have unittest code like the following:

import unittest

class MyUnitTest(unittest.TestCase):
    def setUpClass(self):
        do_something_expensive_for_all_sets_of_tests()

class MyFirstSetOfTests(MyUnitTest):
    def setUpClass(self):
        super(MyFirstSetOfTests, self).setUpClass()
        do_something_expensive_for_just_these_first_tests()

    def test_one(self):
        ...

    def test_two(self):
        ...

class MySecondSetOfTests(MyUnitTest):
    def setUpClass(self):
        super(MySecondSetOfTests, self).setUpClass()
        do_something_expensive_for_just_these_second_tests()

    def test_one(self):
        ...

    def test_two(self):
        ...

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

When I try to run this code, I get an error like this:

======================================================================
ERROR: setUpClass (__main__.MyFirstSetOfTests)
----------------------------------------------------------------------
TypeError: unbound method setUpClass() must be called with MyFirstSetOfTests instance as first argument (got nothing instead)

----------------------------------------------------------------------
  • 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-16T16:16:52+00:00Added an answer on June 16, 2026 at 4:16 pm

    setUpClass must be a class method. From the documentation:

    A class method called before tests in an individual class run. setUpClass is called with the class as the only argument and must be decorated as a classmethod():

    @classmethod
    def setUpClass(cls):
        ...
    

    See Class and Module Fixtures for more details.

    Your version is missing the @classmethod decorator:

    class MyUnitTest(unittest.TestCase):
        @classmethod
        def setUpClass(cls):
            do_something_expensive_for_all_sets_of_tests()
    
    class MyFirstSetOfTests(MyUnitTest):
        @classmethod
        def setUpClass(cls):
            super(MyFirstSetOfTests, cls).setUpClass()
            do_something_expensive_for_just_these_first_tests()
    

    The error is thrown because MyFirstSetOfTests.setUpClass() is called on the class, not on an instance, but you didn’t mark your method as a classmethod and thus it was not passed in the automatic self argument. In the above updated code I used cls instead, to reflect that the name references the class object.

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

Sidebar

Related Questions

I have the following code test_A.py which mocks MyClass.mymethod: from unittest import main from
Ok, So I have the following situation. I originally had some code like this:
I have an abstract class where source code looks like this: /* * @assert
I have the following code: <?php class X { public function do($url) { $httpRequest
Lets say I have the following code in C#: public class AppleTree { public
I have the following code: public class NewsEditViewDataValidator : AbstractValidator<NewsEditViewData> { public NewsEditViewDataValidator() {
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have the following code: #include <iostream> #define BOOST_TEST_MODULE my test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(
I have problem organizing my unittest based class test for family of tests. For
I have the following block of code in a makefile: param_test_dir: @if test -d

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.