zoukankan      html  css  js  c++  java
  • fixture 之 本身自带固定参数

     1 import pytest
     2 source:https://github.com/pytest-dev/pytest/blob/master/doc/en/fixture.rst
     3 
     4 @pytest.fixture(params=[0, 1, pytest.param(2, marks=pytest.mark.skip)])
     5 def data_set(request):
     6     print(request)
     7     print(request.param)
     8     return request.param
     9 
    10 
    11 def test_data(data_set):
    12     pass
    13     
    14 
    15 @pytest.fixture(scope="module", params=["mod1", "mod2"])
    16 def modarg(request):
    17     param = request.param
    18     print("  SETUP modarg", param)
    19     yield param
    20     print("  TEARDOWN modarg", param)
    21 
    22 
    23 @pytest.fixture(scope="function", params=[1, 2])
    24 def otherarg(request):
    25     param = request.param
    26     print("  SETUP otherarg", param)
    27     yield param
    28     print("  TEARDOWN otherarg", param)
    29 
    30 
    31 def test_0(otherarg):
    32     print("  RUN test0 with otherarg", otherarg)
    33 
    34 
    35 def test_1(modarg):
    36     print("  RUN test1 with modarg", modarg)
    37 
    38 
    39 def test_2(otherarg, modarg):
    40     print("  RUN test2 with otherarg {} and modarg {}".format(otherarg, modarg))
    41     
    42 if __name__ == '__main__':
    43     print('start')
    44     pytest.main(["-s", "-v", "testfixture.py"])
    45     print('end')

    执行结果:

    testfixture.py::test_data[0] <SubRequest 'data_set' for <Function test_data[0]>>
    0
    PASSED
    testfixture.py::test_data[1] <SubRequest 'data_set' for <Function test_data[1]>>
    1
    PASSED
    testfixture.py::test_data[2] SKIPPED
    testfixture.py::test_0[1]   SETUP otherarg 1
      RUN test0 with otherarg 1
    PASSED  TEARDOWN otherarg 1
    
    testfixture.py::test_0[2]   SETUP otherarg 2
      RUN test0 with otherarg 2
    PASSED  TEARDOWN otherarg 2
    
    testfixture.py::test_1[mod1]   SETUP modarg mod1
      RUN test1 with modarg mod1
    PASSED
    testfixture.py::test_2[mod1-1]   SETUP otherarg 1
      RUN test2 with otherarg 1 and modarg mod1
    PASSED  TEARDOWN otherarg 1
    
    testfixture.py::test_2[mod1-2]   SETUP otherarg 2
      RUN test2 with otherarg 2 and modarg mod1
    PASSED  TEARDOWN otherarg 2
    
    testfixture.py::test_1[mod2]   TEARDOWN modarg mod1
      SETUP modarg mod2
      RUN test1 with modarg mod2
    PASSED
    testfixture.py::test_2[mod2-1]   SETUP otherarg 1
      RUN test2 with otherarg 1 and modarg mod2
    PASSED  TEARDOWN otherarg 1
    
    testfixture.py::test_2[mod2-2]   SETUP otherarg 2
      RUN test2 with otherarg 2 and modarg mod2
    PASSED  TEARDOWN otherarg 2
      TEARDOWN modarg mod2
  • 相关阅读:
    .NET中对资源文件的使用简介
    jQuery框架学习
    asp.net 性能优化(转)
    走向ASP.NET架构设计(转)
    memcached全面剖析–5. memcached的应用和兼容程序
    ASP.NET MVC
    memcached全面剖析–3.memcached的删除机制和发展方向
    memcached完全剖析–1. memcached的基础
    memcached全面剖析–4. memcached的分布式算法
    memcached全面剖析–2.理解memcached的内存存储
  • 原文地址:https://www.cnblogs.com/Tester_Dolores/p/12898220.html
Copyright © 2011-2022 走看看