Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Created December 5, 2021 23:33
Show Gist options
  • Save tos-kamiya/7922dd022ecbed9d4c9c2081f5734b33 to your computer and use it in GitHub Desktop.
Save tos-kamiya/7922dd022ecbed9d4c9c2081f5734b33 to your computer and use it in GitHub Desktop.
fix: os.chdir in unittest's test case causes a RecursionError on Windows 10
from typing import *
import os
import tempfile
import unittest
class ChdirTest(unittest.TestCase):
def test_chdir(self):
with tempfile.TemporaryDirectory() as tempdir:
curdir = os.getcwd()
try:
os.chdir(tempdir)
print("the current dir is: %s" % tempdir)
finally:
os.chdir(curdir)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment