Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example: with TemporaryWorkingDirectory() as tmpdir: ...
| 39 | |
| 40 | |
| 41 | class TemporaryWorkingDirectory(TemporaryDirectory): |
| 42 | """ |
| 43 | Creates a temporary directory and sets the cwd to that directory. |
| 44 | Automatically reverts to previous cwd upon cleanup. |
| 45 | Usage example: |
| 46 | |
| 47 | with TemporaryWorkingDirectory() as tmpdir: |
| 48 | ... |
| 49 | """ |
| 50 | def __enter__(self): |
| 51 | self.old_wd = _os.getcwd() |
| 52 | _os.chdir(self.name) |
| 53 | return super(TemporaryWorkingDirectory, self).__enter__() |
| 54 | |
| 55 | def __exit__(self, exc, value, tb): |
| 56 | _os.chdir(self.old_wd) |
| 57 | return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb) |
no outgoing calls