pytest使用fixture传递测试数据
#使用usefixtures和在测试方法中添加fixture参数差不多,但是只有后者才能用使用fix的返回值 @pytest.fixture() def some_data(): return (1,"a",None,{"b": 2}) def test_A(some_data): assert some_data[0]==1 def test_B(some_data): assert some_data[1]=="a" def test_C(some_data): assert some_data[2] is None def test_D(some_data): assert some_data[3]["b"]==2 #不能使用这种写法传值,会报错 @pytest.mark.userfixtures("some_data") def test_E(): assert some_data[0] == 1
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/11390237.html