os_tests.py
import os
from os import path
import shutil
def create_dir():
dir = "/home/MOCK/_dir"
if os.path.isdir(_dir):
shutil.rmtree(_dir)
import os
import shutil
from os_tests import create_dir
class Test_unittests(unittest.TestCase):
@patch("os_tests.os.path.isdir")
@patch("os_tests.shutil.rmtree")
def test_create_dir_False(self, mock_os_path_isdir, mock_shutil_rmtree):
mock_os_path_isdir.return_value = False
create_dir()
mock_shutil_rmtree.assert_not_called()
python3 unit02.py
F.
FAIL: test_create_dir_False (main.Test_unittests)
Traceback (most recent call last):
File "/usr/lib/python3.8/unittest/mock.py", line 1325, in patched
return func(*newargs, **newkeywargs)
File "unit02.py", line 22, in test_create_dir_False
mock_shutil_rmtree.assert_not_called()
File "/usr/lib/python3.8/unittest/mock.py", line 874, in assert_not_called
raise AssertionError(msg)
AssertionError: Expected 'isdir' to not have been called. Called 1 times.
Calls: [call('/home/MOCK/_dir'), call().bool()].
enter code here