Nosetests和argparse不允许从命令lin获取参数

2024-09-25 02:28:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了鼻子测试,得到了奇怪的错误信息。你知道吗

import argparse
import nose
from nose.tools import istest


def get_args():
    parser = argparse.ArgumentParser(description='Arguments for running test')
    parser.add_argument('-p1', '--path1', type=str, help='Some help text', required=True)
    parser.add_argument('-p2', '--path2', type=str, help='Some help text', required=True)
    args = parser.parse_args()
    path1 = args.path1
    path2 = args.path2
    return path1, path2
nose.run()


@istest
def my_test(my_path1=get_args()[0], my_path2=get_args()[0]):
    print my_path1, my_path2
    pass

我用命令nosetests --tests=my_file -p1 some_arg1 -p2 some_arg2开始测试 但输出显示错误

nosetests: error: no such option: -1

如何使用nostest从命令行获取参数并修复此错误? 提前谢谢。你知道吗


Tags: testimportaddparsergetmydefargparse