Posts

Showing posts with the label python-mock

How to convert csv into mock when csv file is specified as argument in unit test of Django command

How to convert csv into mock when csv file is specified as argument in unit test of Django command There is a django command that gives the path of the csv file as an argument as follows. class Command(NoticeCommand): def add_arguments(self, parser): parser.add_argument( '--file', dest="file", type=str, required=True ) def handle(self, *args, **options): with open(options['file'], 'r') as f: reader = csv.reader(f) next(reader) for row in reader: ... I am thinking to make this csv file mock when doing unit test. However, I do not know which part and how to make mock. Also, the argument is required = True . How can I call UnitTest when csv is mocked? required = True from mock import patch from django.core.management import call_command class ImportCsvTest(TestCase): @patch("common.management.commands.import_csv.????") def test_import_csv(self...