How to test a function in Python which creates a directory? Can you give an example make_directory_test() function?
def make_directory(directory):
if not os.path.exists(directory):
os.makedirs(directory)
Just test that directory exists
def test_make_directory(self):
directory_path = '...' # somepath
make_directory(directory_path)
self.assertTrue(os.path.exists(directory_path))
And do ensure that any directories created in unit tests are deleted after each tests in tearDown or setUp, to ensure independency of tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With