Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytest解析参数并比较输出文件_Python_Pytest - Fatal编程技术网

Python pytest解析参数并比较输出文件

Python pytest解析参数并比较输出文件,python,pytest,Python,Pytest,我编写了一个程序,通过以下命令在终端中运行 python simulation.py -f data_file.dat simulate.py脚本需要一个输入来运行“-f”,然后是文件名。脚本在运行过程中写入图像文件和平均.csv文件 我是第一次编写测试代码,并为simulate.py中的大多数函数实现了单元测试 现在我想为一些图像和average.csv编写测试代码,然后对实际==预期图像和csv进行差异检查。但是,这些文件是使用加法计算生成的,因此检查它们是否工作的唯一方法是运行计算并选择

我编写了一个程序,通过以下命令在终端中运行

python simulation.py -f data_file.dat
simulate.py脚本需要一个输入来运行“-f”,然后是文件名。脚本在运行过程中写入图像文件和平均.csv文件

我是第一次编写测试代码,并为simulate.py中的大多数函数实现了单元测试

现在我想为一些图像和average.csv编写测试代码,然后对实际==预期图像和csv进行差异检查。但是,这些文件是使用加法计算生成的,因此检查它们是否工作的唯一方法是运行计算并选择特定的迭代来检查实际与预期

  • 如何使用pytest运行带有参数的脚本simulate.py

  • 将新文件与预期文件进行比较的最佳做法是什么?我应该读取测试代码中新生成的数据并与预定义的预期文件进行比较吗

  • 我尝试使用以下方法编写一个test_case.py:

    import argparse
    import pytest   
    
    ap = argparse.ArgumentParser()
    ap.add_argument("-f", required =True, default = "map.dat")
    args = vars(ap.parse_args())
    
    然后运行命令pytest,这将导致错误:

    ------------------------------ Captured stderr --------------------------------
    usage: pytest [-h] -f F
    pytest: error: the following arguments are required: -f
    =========================== short test summary info ============================
    ERROR test_case.py - SystemExit: 2
    !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!