有一个django命令,它将csv文件的路径作为参数,如下所示。你知道吗
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:
...
我正在考虑在进行单元测试时模拟这个csv文件。
但是,我不知道该用哪一部分和如何制作mock。
另外,参数是required = True
。当csv被模拟时,我如何调用UnitTest?你知道吗
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):
call_command("import_lyric_artists", file=?????)
有关更多示例,请参阅python documentation。你知道吗
相关问题 更多 >
编程相关推荐