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 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 this code class Test(object): def start_conn(self): pass def __init__(self): self.conn =
say I have: class Test { public static int Hello = 5; } This
Say I have a vector: (def data [Hello World Test This]) And I want
so i have ruby script that simply writes to a test.txt file with hello
I have the following data in my database (comma separated strings): word, test, hello
I have two arrays: $array1 = array(1=>1,10=>1,12=>0,13=>13); $array2 = array(1=>Hello,10=>Test,12=>check,13=>error); Here $array1 has keys
hello i have this question i was trying to find a way to call
I have test method in helpers/application_helper.rb file: def test concat(Hello world) end Then, in
So I have this test code to send HELLO over a USB serial port:
Just starting using the Firebug console. I have a test script which I'll post

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.