相关疑难解决方法(0)

如果py.test的另一个测试失败,我怎么能跳过测试?

假设我有这些测试功能:

def test_function_one():
    assert # etc...

def test_function_two():
    # should only run if test_function_one passes
    assert # etc.
Run Code Online (Sandbox Code Playgroud)

如果test_function_one通过,我怎样才能确保test_function_two只运行(我希望它可能)?

编辑: 我需要这个,因为测试二使用测试验证的属性.

python pytest

10
推荐指数
2
解决办法
2111
查看次数

[py.test]:测试依赖项

我正在使用py.test编写测试系统,并根据其他一些测试运行结果寻找一种方法来执行特定的测试.

例如,我们有标准的测试类:

import pytest

class Test_Smoke:
   def test_A(self):
       pass

   def test_B(self):
       pass

   def test_C(self):
       pass
Run Code Online (Sandbox Code Playgroud)

如果传递test_A()和test_B(),则应执行test_C(),否则 - 跳过.

我需要一种在测试或测试类级别上执行此类操作的方法(例如,如果传递了所有Test_Smoke,则执行Test_Perfo),并且我无法使用标准方法(如@ pytest.mark.skipif)找到解决方案.

用pytest可以吗?

python pytest

7
推荐指数
1
解决办法
4430
查看次数

如果特定的测试失败,则无法进行pytest测试

所以我有一个目录,里面填充了一堆用python编写的测试,并用正确的语法确保它们按顺序运行.

所以假设我有一个测试,如果失败,当前调用pytest.exit('Exit Message').这个问题是XML生成的测试输出只记录它之前的测试.我希望整个套件运行但如果上述测试失败则报告为失败.

我想到的解决方案是设置一个环境变量,以防它失败,然后在下面的测试中检查该环境变量.问题是用Jenkins运行它,没有检测到环境变量集,如果它存在,我更喜欢原生解决方案.

我有的是:

def test_check_connection(self):
    ...
    if Failed:
        pytest.exit('No connectivity')
Run Code Online (Sandbox Code Playgroud)

python pytest jenkins

5
推荐指数
1
解决办法
1567
查看次数

如何在Pytest中控制增量测试用例

@pytest.mark.incremental
class Test_aws():

    def test_case1(self):
        ----- some code here ----
        result = someMethodTogetResult
        assert result[0] == True
        orderID = result[1]

    def test_case2(self):
        result = someMethodTogetResult # can be only perform once test case 1 run successfully.
        assert result == True

    def test_deleteOrder_R53HostZonePrivate(self):
        result = someMethodTogetResult
        assert result[0] == True
Run Code Online (Sandbox Code Playgroud)

当前行为是:如果测试1通过,则测试2运行,如果测试2通过,则测试3运行。

我需要的是:如果test_case 1通过则应该运行test_case 3。test_case 2不应更改任何行为。有什么想法吗?

python pytest python-2.7

3
推荐指数
1
解决办法
539
查看次数

pytest在类中以正确的顺序运行场景

所以我有以下结构:

class Test(object):

   def test_1(self):
      pass

   def test_2(self):
      pass

   def test_3(self):
      pass
Run Code Online (Sandbox Code Playgroud)

它运行得很好,现在我正在添加"方案"(因为它建议在pytest - 一个快速的"testscenarios"端口):

def pytest_generate_tests(metafunc):
    idlist = []
    argvalues = []
    for scenario in metafunc.cls.scenarios:
        idlist.append(scenario[0])
        items = scenario[1].items()
        argnames = [x[0] for x in items]
        argvalues.append(([x[1] for x in items]))
    metafunc.parametrize(argnames, argvalues, ids=idlist)

class Test(object):
       scenarios = ['1' {'arg':'value1'},
                    '2' {'arg':'value2'}]

       def test_1(self, arg):
          pass

       def test_2(self, arg):
          pass

       def test_3(self, arg):
          pass
Run Code Online (Sandbox Code Playgroud)

当我运行它时测试顺序是错误的,我得到:

test_1[1]  
test_1[2]  
test_2[1]   
test_2[2]  
test_3[1]  
test_3[2]
Run Code Online (Sandbox Code Playgroud)

看起来并不像Test类的场景. …

python pytest

1
推荐指数
1
解决办法
4230
查看次数

标签 统计

pytest ×5

python ×5

jenkins ×1

python-2.7 ×1