Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

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


Release history Release notifications

Download files

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

Files for temp_dir, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size temp_dir-0.1.1.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page