首页 > TAG信息列表 > metafunc

Python的hook函数(pytest_generate_tests())进行测试的参数化

  pytest_generate_tests()函数 1.介绍 pytest_generate_tests这个Hook函数是在Pytest收集测试用例时被调用,它有一个参数metafunc,可以获得测试函数的上下文信息,并且可以调用metafunc.parametrize()对测试函数进行参数化。 2.该hook函数存放的位置 pytest_generate_tests()函数编写在

pytest的参数化

参数化有两种方式: 1、 @pytest.mark.parametrize 2、利用conftest.py里的 pytest_generate_tests   1中的例子如下: @pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)])def test_eval(test_input, expected):

pytest学习笔记

测试数据驱动 Here is an example pytest_generate_tests function implementing a parametrization scheme similar to Michael Foord’s unittest parametrizer but in a lot less code:,unittest也有这样的设计:https://github.com/testing-cabal/unittest-ext/blob/maste