zoukankan      html  css  js  c++  java
  • python内置函数eval()在测试脚本断言中的应用

    理论:https://www.runoob.com/python/python-func-eval.html

    eval():用来执行一个字符串表达式,并返回表达式的值。

    在实际中的应用举例:

    from api.alert_info_controller.api_analysisType import ApiAnalysisType
    
    
    class TestAnalysisType:
        def test_analysisType(self):
            res = ApiAnalysisType().analysisType()
            str = "res.json()['data'] is not None"
            assert res.status_code == 200
            assert eval(str)     # 此时会返回True或者False

    可看到该测试用例的执行结果为pass

     

    也可以在数据驱动中使用:

    class TestZone:
        @pytest.mark.parametrize("keyword,expected", [(None, "res.json() is not None"), ("鼓楼医院", "not res.json() is None")])
        def test_zoneForReport(self, keyword, expected):
            res = ApiZone().zoneForReport(keyword)
            assert eval(expected)
  • 相关阅读:
    2018-div-matrix
    cf663div2
    生成树
    Call to your teacher
    并查集总结
    分组背包
    被3整除的子序列
    多重背包
    12.05
    django生命周期图
  • 原文地址:https://www.cnblogs.com/wang-mengmeng/p/12593661.html
Copyright © 2011-2022 走看看