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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:26+00:00 2026-05-13T11:42:26+00:00

I have a script that acts as a wrapper for some unit tests written

  • 0

I have a script that acts as a wrapper for some unit tests written using the Python unittest module. In addition to cleaning up some files, creating an output stream and generating some code, it loads test cases into a suite using

unittest.TestLoader().loadTestsFromTestCase()

I am already using optparse to pull out several command-line arguments used for determining the output location, whether to regenerate code and whether to do some clean up. I also want to pass a configuration variable, namely an endpoint URI, for use within the test cases.

I realize I can add an OptionParser to the setUp method of the TestCase, but I want to instead pass the option to setUp. Is this possible using loadTestsFromTestCase()? I can iterate over the returned TestSuite‘s TestCases, but can I manually call setUp on the TestCases?

** EDIT **
I wanted to point out that I am able to pass the arguments to setUp if I iterate over the tests and call setUp manually like:

(options, args) = op.parse_args()
suite = unittest.TestLoader().loadTestsFromTestCase(MyTests.TestSOAPFunctions)
for test in suite:
    test.setUp(options.soap_uri)

However, I am using xmlrunner for this and its run method takes a TestSuite as an argument. I assume it will run the setUp method itself, so I would need the parameters available within the XMLTestRunner.

  • 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-13T11:42:27+00:00Added an answer on May 13, 2026 at 11:42 am

    Well, I want to do the same thing and was going to ask this question myself. I wanted to improve over the following code because it has duplication. It does let me send in arguments to test TestCase however:

    import unittest
    import helpspot
    
    class TestHelpSpot(unittest.TestCase):
        "A few simple tests for HelpSpot"
    
        def __init__(self, testname, path, user, pword):
            super(TestHelpSpot, self).__init__(testname)
            self.hs = helpspot.HelpSpot(path, user, pword)
    
        def test_version(self):
            a = self.hs.version()
            b = self.hs.private_version()
            self.assertEqual(a, b)
    
        def test_get_with_param(self):
            a = self.hs.filter_get(xFilter=1)
    
        def test_unknown_method(self):
            self.assertRaises(helpspot.HelpSpotError, self.hs.private_wuggienorple)
    
    if __name__ == '__main__':
        import sys
        user = sys.argv[1]
        pword = sys.argv[2]
        path = sys.argv[3]
    
        test_loader = unittest.TestLoader()
        test_names = test_loader.getTestCaseNames(TestHelpSpot)
    
        suite = unittest.TestSuite()
        for test_name in test_names:
            suite.addTest(TestHelpSpot(test_name, path, user, pword))
    
        result = unittest.TextTestRunner().run(suite)
        sys.exit(not result.wasSuccessful())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 418k
  • Answers 418k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since you found out already... * ...how to separate multipage… May 15, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer Try this: $last_cite = $("strong ~ cite:last"); if ($last_cite.length >… May 15, 2026 at 9:52 am
  • Editorial Team
    Editorial Team added an answer What you did only removes the association between an article… May 15, 2026 at 9:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.