2016-08-15 4 views

답변

0

제안한대로 내 솔루션에는 @mock.patch() 데코레이터가 필요합니다. 난 당신이 [mock.patch()] (https://docs.python.org/3/library/unittest.mock.html#unittest.mock을 찾고 생각

from django.test import TestCase, mock 
from my_app.scan_files import my_method_that_return_count_of_files 

mock_one_file = mock.MagicMock(return_value = ['one_file', ]) 

class MyMethodThatReturnCountOfFilesfilesTestCase(TestCase): 
    @mock.patch('os.scandir', mock_one_file) 
    def test_get_one(self): 
     """ Test it receives 1 (one) file """ 
     files_count = my_method_that_return_count_of_files('/anything/') 
     self.assertEqual(files_count, 1) 
관련 문제