Skip to main content

Execute block of code within a temporary directory

Project description

Change into newly created temporary directory for executing a block of code.

Upon leaving the code block the temporary directory and all its contents are removed and the original working directory is restored.

Intended as a tool to ease “integration” testing.

The package contains only two functions: in_temp_dir to be used with the with statement and within_temp_dir to decorate a function.

Examples

Function decorator:

@within_temp_dir
def f():
    return os.getcwd()


class TestScript(unittest.TestCase):

    @within_temp_dir
    def test_output_file_created(self):
        self.create_input_file()
        call_script('input')
        self.assertTrue(os.path.exists('output'))

Context manager:

with in_temp_dir():
    with open('tempfile', 'w') as f:
        f.write(...)
    process_file('tempfile')

Similar functionality elsewhere

Similar functionality can be found at

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

temp_dir-0.1.1.tar.gz (2.7 kB view details)

Uploaded Source

File details

Details for the file temp_dir-0.1.1.tar.gz.

File metadata

  • Download URL: temp_dir-0.1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for temp_dir-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d11a43aef656bb00cdcd89e159803f88c5cc8a3aa4ca40c45bb7e5fd02c8bb5f
MD5 ea8e9ac38b3963311b2681c735ff87b2
BLAKE2b-256 ae111decdc521eb191f4ecef1d71c88366fae5fecf0506fd270ae099581ae299

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page