zoukankan      html  css  js  c++  java
  • pytest 用 @pytest.mark.usefixtures("fixtureName")装饰类,可以让执行每个case前,都执行一遍指定的fixture

    conftest.py

    1 import pytest
    2 import uuid
    3 
    4 @pytest.fixture()
    5 def declass():
    6     print("declass:"+str(uuid.uuid4()))
    7     return "declass"

    test_forclass.py
     1 import pytest
     2 
     3 
     4 @pytest.mark.usefixtures("declass")
     5 class TestClass(object):
     6     def test_case1(self):
     7         print("test_case1:")
     8         assert 0==0
     9 
    10 
    11     def test_case2(self):
    12         print("test_case2:")
    13         assert 0 == 0

    执行结果:

    可以从结果中看到每个case执行前,都执行了declass这个fixture,且每次都是重新调用。  (这种使用方法,从官方给出的例子来看,应该用于数据清理或准备比较合适。)

    还支持引用多个fixture

    conftest.py

     1 import pytest
     2 import uuid
     3 
     4 @pytest.fixture()
     5 def declass():
     6     print("declass:"+str(uuid.uuid4()))
     7     return "declass"
     8 
     9 @pytest.fixture()
    10 def declass2():
    11     print("declass2:"+str(uuid.uuid4()))
    12     return "declass2"

    test_forclass.py
     1 @pytest.mark.usefixtures("declass","declass2")
     2 class TestClass(object):
     3     def test_case1(self):
     4         print("test_case1:")
     5         assert 0==0
     6 
     7 
     8     def test_case2(self):
     9         print("test_case2:")
    10         assert 0 == 0

    执行结果:

  • 相关阅读:
    Jmeter报告优化之New XSL stylesheet
    生成html报告
    描述性统计与性能结果分析
    聚合报告
    IPTV系统的VOD与TV业务性能测试
    JMeter 中的如何区分 Server Time 和 Network Time
    "并发用户数量"的正确英文表示
    Jmeter测试结果分析(下)
    Jmeter测试结果分析(上)
    Struts2简介
  • 原文地址:https://www.cnblogs.com/moonpool/p/11352207.html
Copyright © 2011-2022 走看看