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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:34:00+00:00 2026-05-16T04:34:00+00:00

Can I call a test method from within the test class in python? For

  • 0

Can I call a test method from within the test class in python? For example:


class Test(unittest.TestCase):
    def setUp(self):
        #do stuff

    def test1(self):
        self.test2()

    def test2(self):
        #do stuff

update: I forgot the other half of my question. Will setup or teardown be called only after the method that the tester calls? Or will it get called between test1 entering and after calling test2 from test1?

  • 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-16T04:34:01+00:00Added an answer on May 16, 2026 at 4:34 am

    Try running the following code:

    import unittest
    
    class Test(unittest.TestCase):
        def setUp(self):
            print 'Setting Up'
    
        def test1(self):
            print 'In test1'
            self.test2()
    
        def test2(self):
            print 'In test2'
    
        def tearDown(self):
            print 'Tearing Down'
    
    if __name__ == '__main__':
        unittest.main()
    

    And the results is:

    Setting Up
    In test1
    In test2
    Tearing Down
    .Setting Up
    In test2
    Tearing Down
    .
    ----------------------------------------------------------------------
    Ran 2 tests in 0.000s
    
    OK
    

    Now you see, setUp get called before a test method get called by unittest, and tearDown is called after the call.

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

Sidebar

Related Questions

I am getting: Can't call method test without a package or object reference at
Let's say I have a subroutine/method that a user can call to test some
I have a method under test. Within its call stack, it calls a DAO
From this code I can call bmwCars.CopyToDataTable() as I expected. var bmwCars = from
Using a delegate I can call any function asynchronously. From the documentation I understand
(Yes I know I can call Java code from Scala; but that is pointless;
I have a C function in MyClass and can call it from inside that
I want to call browser window resize method using jquery from with in iframe.
I'm testing a method that calls another method within the same class. Depending on
I'm trying to call a method of another class but this causes my app

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.