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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:45:47+00:00 2026-05-14T21:45:47+00:00

Hello I have test’s using unittest. I have a test suite and I am

  • 0

Hello I have test’s using unittest. I have a test suite and I am trying to pass variables through into each of the tests. The below code shows the test suite used.

class suite():

    def suite(self): #Function stores all the modules to be tested

        modules_to_test = ('testmodule1', 'testmodule2')
        alltests = unittest.TestSuite()
        for module in map(__import__, modules_to_test):
            alltests.addTest(unittest.findTestCases(module))
        return alltests

It calls tests, I would like to know how to pass variables into the tests from this class. An example test script is below:

class TestThis(unittest.TestCase):
    def runTest(self):
        assertEqual('1', '1')

class TestThisTestSuite(unittest.TestSuite):

    # Tests to be tested by test suite
    def makeTestThisTestSuite():
        suite = unittest.TestSuite()
        suite.addTest("TestThis")
        return suite

    def suite():
        return unittest.makeSuite(TestThis)


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

So from the class suite() I would like to enter in a value to change the value that is in assert value. Eg. assertEqual(self.value, '1'). I have tried sys.argv for unittest and it doesn’t seem to work.
Thanks for any help.

  • 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-14T21:45:47+00:00Added an answer on May 14, 2026 at 9:45 pm

    Passing interactive values on the command line is not really in line with the intention of automated unit tests. How about using the ConfigParser library module and have your TestCase subclass’s __init__ method load some variable test input data that way?

    Of course, sticking with the code you have, what about either module global variables or class constant members to hold your test data? For example, after you import a test module by name, couldn’t you just do

    module.testVars = [1, 2, 3, "foo"]
    

    And have the tests in the test modules reference that variable (which might be an empty list by default)?

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

Sidebar

Related Questions

Hello i have new Problem with Add Form my problem here WARNING: /test.xhtml @24,173
For example i have this string: $test_str = num Test \n num Hello \n
I have a simple web service as below /** * Test web service */
I have a test.php page in this page , there is a url .
I'm using the Hello World with Ant tutorial from the Ant manual to learn
Hello fellow computer people :) I have a shell script that I will use
Hello another question concerning debugging : Automatically generating test cases when i know the
Multi-Test TestNG.xml file results in java.lang.NullPointerException Hello Quality Team, I need help getting TestNG
I have a number of directories containing the files similar to the below example:
I need to strip out a few invalid characters from a string and wrote

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.