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进行差异检查。但是,这些文件是使用加法计算生成的,因此检查它们是否工作的唯一方法是运行计算并选择特定的迭代来检查实际与预期
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 !!!!!!!!!!!!!!!!!!!!