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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:58:35+00:00 2026-05-20T21:58:35+00:00

I would like to unit-test the functionality of a few classes that mainly do

  • 0

I would like to unit-test the functionality of a few classes that mainly do file in- and output. Furthermore I would like to do that on multiple cores (–jobs=4).

The problem is, that the files that are created by the classes often have the same name and they get mixed up in multiple threads. What I do currently is that I run each unit-test in a separate directory like so:

def test(self):
  if os.path.exists("UniqueDir"):
    os.system("rm -rf UniqueDir")
  os.mkdir("UniqueDir")
  os.chdir("UniqueDir")
  #Do the actual testing
  os.chdir("..")
  os.rmdir("UniqueDir")

The downsides are very obvious:

  1. Each test must receive a unique directory name
  2. Each test has this overhead of source which really is not pleasant to look at at all

What approach could I use to 1. separate my tests from one another but 2. do it in a more elegant way?

Any help, suggestion etc. is appreciated!

Cherio Woltan

  • 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-20T21:58:36+00:00Added an answer on May 20, 2026 at 9:58 pm

    I would suggest to use the unittest module and build the classes like this:

    import unittest
    from tempfile import mkdtemp
    
    class Test(unittest.TestCase):
    
        def setUp(self):
            self.tempdir = mkdtemp()
            os.chdir(self.tempdir)
    
        def tearDown(self):
            os.rmdir(self.tempdir)
    
        def testName(self):
            #Do the actual testing
            pass
    
    if __name__ == "__main__":
        unittest.main()
    

    Additionally you could add multiprocessing to create 4 threads.

    Edit: removed the os.mkdir because mkdtemp creates a temp directory so it’s bogus. Thx Sebastian.

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

Sidebar

Related Questions

I have some classes(call it Class A) which I would like to unit test
What would a simple unit test look like to confirm that a certain controller
I would like to unit test an Add method in a repository that returns
I would like to test a process that queries across multiple schemas using PHPUnit's
I have various methods that I would like to unit test using Visual Studio's
I would like to unit test a DEPENDENT service layer which allows me to
I would like to write the unit test for a text parser class but
I have some Objective-C [i-os] code that I would like to run unit tests
I'm working with the Struts2 framework and would like to unit test the execute
I would like to write unit tests to test whether a dependency exists between

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.