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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:46:56+00:00 2026-05-15T14:46:56+00:00

What I would like to do, is create a folder, where people can put

  • 0

What I would like to do, is create a folder, where people can put in a file for testing, and have pyunit automatically expand in order to run the test as a separate test. Currently, what I’m doing is:

class TestName(unittest.testcase):
    def setUp(self):
        for file in os.listdir(DIRECTORY):
            # Setup Tests

    def test_comparison(self):
        for file in os.listdir(DIRECTORY):
            # Run the tests

def suite():
    return unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(TestName),
])

if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=2).run(suite())

Obviously there is many problems with that, such as if any test fails, the whole thing fails, etc. etc. What I would like to do, is set up pyunit so that it will run a test (or a test case), for each file that is placed in the directory. Now, what I’m thinking I could do is create the class listed above, with just the two methods, but in order to do that successfully, I would have to add in a context parameter, eg:

def setUp(self, filepath):
    # Do stuff

Then I could put the loop in the main chunk of code, and run the tests like this:

def suite():
    return unittest.TestSuite([
unittest.TestLoader().loadTestsFromTestCase(TestName, file),
])

if __name__ == "__main__":
    for file in DIRECTORY:
        unittest.TextTestRunner(verbosity=2).run(suite(file))

But I’m not sure how to do that without nearly rewriting the hole unittest.TestCase() class. Is there any way I could do that, or is there any other way I can geta dynamically expanding set of tests/test cases depending on how many files are in a folder? Thanks.

  • 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-15T14:46:57+00:00Added an answer on May 15, 2026 at 2:46 pm

    You could use nose support for test generators. This would look something like this:

    def test_comparison():
        for file in os.listdir(DIRECTORY):
            yield run_cmp_test, file
    
    def run_cmp_test(file):
        # Run the tests
    

    Alternatively you could also funcargs in py.test.

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

Sidebar

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.