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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:08:39+00:00 2026-06-13T19:08:39+00:00

I know how to create a temporary directory in Python using tempfile . I

  • 0

I know how to create a temporary directory in Python using tempfile.

I have though a class that encapsulates the user environment. I have also a Unit test which creates a temporary dummy user environment and populates it with some files that are used for testing. After this is done I want to clean everything up, thus removing everything from that dummy user directory (using shutils.rmtree)

I have a dummy class wrapping the original one that prevents it from getting the real user directory and returns the dummy instead. Though I’m afraid somebody might forget this and perhaps change it or completely remove the wrapper class. This might work and the developer will end up loosing everything from his/her home directory. Though this might teach him/her a good lesson, it is not acceptable.

I can check that ‘/tmp/’ is at the path start of the user home, so that I know it’s safe to delete, but that won’t work with windows. As tempfile already knows how to create a directory it would be also able to tell if a directory is in the temporal area.
Though I can’t find out how to do it.

Any ideas?

  • 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-06-13T19:08:41+00:00Added an answer on June 13, 2026 at 7:08 pm

    This is what tempfile.gettempdir() is for.

    However, you may want rethink how you signal that the ‘home directory’ is a temporary test-only setup. You could add an extra file (.this-is-a-test-homedir or similar), use a clear ‘temporary’ username.

    Or, better yet, remove the dummy wrapper altogether and have the test create the temporary user directory before running the test, then clean it up when tearing down the test.

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

Sidebar

Related Questions

I have an application that in a certain moment has to create a temporary
I know I can create a plot with line and dots using the type
Of what I know of benefits of using initialization list is that they provide
I have a MySQL stored procedure that uses a temporary table. Assume that my
I'm using a stored procedure to create a temporary table and want to return
I have a python script that works great when run by itself. Based on
I know you can create a temporary file with tmpfile and than write to
I have a simple java program that creates a series of temporary files stored
Possible Duplicate: Create a temporary directory in Java Duplicate: stackoverflow.com/questions/375910 Is there a way
I need to create a temporary file to send it, I have tried :

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.