0

如何对 pytest 的函数进行参数化,以便从文本文件中获取参数,并在每次迭代时更改函数名称以获取 pytest-html 报告

文本文件格式:Function_name | 断言值 | 从 postgresql 查询断言。

要求:创建一个基于pytest的框架

到目前为止,我的逻辑(它不起作用):

with open("F_Query.txt","r") as ins1:
    for F_Query in ins1:
        #Name of function to be executed to be extracted from the file differentiated with delimeter " | "(leading and trailing space required)
        F_name=F_Query.split(" | ")[0]
        assert_val=F_Query.split(" | ")[1]
        Query=F_Query.split(" | ")[2]
        Loc_file=(Query.split(" ")[-5:])[0]
        def f(text):
            def r(y):
                return y
            r.__name__ = text
            return r
            c1.execute(Query)
            assert(c1.rowcount() == assert_val), "Please check output file for records"
        p = f(F_name)

任何人都可以解释如何在每次迭代中更改函数名称,同时在 pytest fun 中传递参数

latest changes (still doesn't work):
with open("F_Query.txt","r") as ins1:
    for F_Query in ins1:
        #Name of function to be executed to be extracted from the file differentiated with delimeter " | "(leading and trailing space required)
        #F_name=F_Query.split(" | ")[0]
        assert_val=int(F_Query.split(" | ")[1])
        Query=F_Query.split(" | ")[2]
        Query=Query.strip("\n")
        #Loc_file=(Query.split(" ")[-5:])[0]
        dictionary1[Query]=assert_val


@pytest.mark.parametrize('argumentname',dictionary1)
def test_values(argumentname):
    c1.execute(dictionary1.keys(argumentname))
    assert(c1.rowcount==dictionary1.values(argumentname))
4

0 回答 0