<i id='Jk3Ub'><tr id='Jk3Ub'><dt id='Jk3Ub'><q id='Jk3Ub'><span id='Jk3Ub'><b id='Jk3Ub'><form id='Jk3Ub'><ins id='Jk3Ub'></ins><ul id='Jk3Ub'></ul><sub id='Jk3Ub'></sub></form><legend id='Jk3Ub'></legend><bdo id='Jk3Ub'><pre id='Jk3Ub'><center id='Jk3Ub'></center></pre></bdo></b><th id='Jk3Ub'></th></span></q></dt></tr></i><div id='Jk3Ub'><tfoot id='Jk3Ub'></tfoot><dl id='Jk3Ub'><fieldset id='Jk3Ub'></fieldset></dl></div>
    • <bdo id='Jk3Ub'></bdo><ul id='Jk3Ub'></ul>

    <tfoot id='Jk3Ub'></tfoot>

    <small id='Jk3Ub'></small><noframes id='Jk3Ub'>

    <legend id='Jk3Ub'><style id='Jk3Ub'><dir id='Jk3Ub'><q id='Jk3Ub'></q></dir></style></legend>

      如果一个失败了,如何跳过课堂上的其余测试?

      时间:2023-09-12
      • <bdo id='ompyY'></bdo><ul id='ompyY'></ul>

        <small id='ompyY'></small><noframes id='ompyY'>

                  <tbody id='ompyY'></tbody>
                <legend id='ompyY'><style id='ompyY'><dir id='ompyY'><q id='ompyY'></q></dir></style></legend>
              1. <tfoot id='ompyY'></tfoot>
                <i id='ompyY'><tr id='ompyY'><dt id='ompyY'><q id='ompyY'><span id='ompyY'><b id='ompyY'><form id='ompyY'><ins id='ompyY'></ins><ul id='ompyY'></ul><sub id='ompyY'></sub></form><legend id='ompyY'></legend><bdo id='ompyY'><pre id='ompyY'><center id='ompyY'></center></pre></bdo></b><th id='ompyY'></th></span></q></dt></tr></i><div id='ompyY'><tfoot id='ompyY'></tfoot><dl id='ompyY'><fieldset id='ompyY'></fieldset></dl></div>
                本文介绍了如果一个失败了,如何跳过课堂上的其余测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在使用 Jenkins、Python、Selenium2(webdriver) 和 Py.test 框架为 Web 测试创建测试用例.

                I'm creating the test cases for web-tests using Jenkins, Python, Selenium2(webdriver) and Py.test frameworks.

                到目前为止,我按以下结构组织测试:

                So far I'm organizing my tests in the following structure:

                每个Class都是Test Case,每个test_方法都是Test Step.

                当一切正常时,此设置效果很好,但是当一个步骤崩溃时,其余的测试步骤"就会变得疯狂.在 teardown_class() 的帮助下,我能够将失败包含在类(测试用例)中,但是我正在研究如何改进它.

                This setup works GREAT when everything is working fine, however when one step crashes the rest of the "Test Steps" go crazy. I'm able to contain the failure inside the Class (Test Case) with the help of teardown_class(), however I'm looking into how to improve this.

                如果其中一个失败了,我需要以某种方式跳过(或 xfail)一个类中的其余 test_ 方法,以便其余测试用例不会运行并标记为失败(因为那会是误报)

                What I need is somehow skip(or xfail) the rest of the test_ methods within one class if one of them has failed, so that the rest of the test cases are not run and marked as FAILED (since that would be false positive)

                谢谢!

                更新:我没有寻找或回答这是不好的做法",因为这样称呼它是非常有争议的.(每个测试类都是独立的——这就足够了).

                UPDATE: I'm not looking or the answer "it's bad practice" since calling it that way is very arguable. (each Test Class is independent - and that should be enough).

                更新 2: 在每个测试方法中添加if"条件不是一种选择 - 需要大量重复工作.我正在寻找的是(也许)有人知道如何使用 钩子 到类方法.

                UPDATE 2: Putting "if" condition in each test method is not an option - is a LOT of repeated work. What I'm looking for is (maybe) somebody knows how to use the hooks to the class methods.

                推荐答案

                我喜欢一般的测试步骤"想法.我将其称为增量"测试,恕我直言,它在功能测试场景中最有意义.

                I like the general "test-step" idea. I'd term it as "incremental" testing and it makes most sense in functional testing scenarios IMHO.

                这是一个不依赖于 pytest 内部细节的实现(除了官方的钩子扩展).将此复制到您的 conftest.py 中:

                Here is a an implementation that doesn't depend on internal details of pytest (except for the official hook extensions). Copy this into your conftest.py:

                import pytest
                
                def pytest_runtest_makereport(item, call):
                    if "incremental" in item.keywords:
                        if call.excinfo is not None:
                            parent = item.parent
                            parent._previousfailed = item
                
                def pytest_runtest_setup(item):
                    previousfailed = getattr(item.parent, "_previousfailed", None)
                    if previousfailed is not None:
                        pytest.xfail("previous test failed (%s)" % previousfailed.name)
                

                如果您现在有这样的test_step.py":

                If you now have a "test_step.py" like this:

                import pytest
                
                @pytest.mark.incremental
                class TestUserHandling:
                    def test_login(self):
                        pass
                    def test_modification(self):
                        assert 0
                    def test_deletion(self):
                        pass
                

                然后运行它看起来像这样(使用 -rx 报告 xfail 原因):

                then running it looks like this (using -rx to report on xfail reasons):

                (1)hpk@t2:~/p/pytest/doc/en/example/teststep$ py.test -rx
                ============================= test session starts ==============================
                platform linux2 -- Python 2.7.3 -- pytest-2.3.0.dev17
                plugins: xdist, bugzilla, cache, oejskit, cli, pep8, cov, timeout
                collected 3 items
                
                test_step.py .Fx
                
                =================================== FAILURES ===================================
                ______________________ TestUserHandling.test_modification ______________________
                
                self = <test_step.TestUserHandling instance at 0x1e0d9e0>
                
                    def test_modification(self):
                >       assert 0
                E       assert 0
                
                test_step.py:8: AssertionError
                =========================== short test summary info ============================
                XFAIL test_step.py::TestUserHandling::()::test_deletion
                  reason: previous test failed (test_modification)
                ================ 1 failed, 1 passed, 1 xfailed in 0.02 seconds =================
                

                我在这里使用xfail"是因为跳过是针对错误的环境或缺少依赖项、错误的解释器版本.

                I am using "xfail" here because skips are rather for wrong environments or missing dependencies, wrong interpreter versions.

                请注意,您的示例和我的示例都不能直接用于分布式测试.为此,pytest-xdist 插件需要开发一种方法来定义组/类,以将其整体发送到一个测试从属设备,而不是当前通常将一个类的测试功能发送到不同从属设备的模式.

                Note that neither your example nor my example would directly work with distributed testing. For this, the pytest-xdist plugin needs to grow a way to define groups/classes to be sent whole-sale to one testing slave instead of the current mode which usually sends test functions of a class to different slaves.

                这篇关于如果一个失败了,如何跳过课堂上的其余测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  <tbody id='NAZgI'></tbody>

                  1. <i id='NAZgI'><tr id='NAZgI'><dt id='NAZgI'><q id='NAZgI'><span id='NAZgI'><b id='NAZgI'><form id='NAZgI'><ins id='NAZgI'></ins><ul id='NAZgI'></ul><sub id='NAZgI'></sub></form><legend id='NAZgI'></legend><bdo id='NAZgI'><pre id='NAZgI'><center id='NAZgI'></center></pre></bdo></b><th id='NAZgI'></th></span></q></dt></tr></i><div id='NAZgI'><tfoot id='NAZgI'></tfoot><dl id='NAZgI'><fieldset id='NAZgI'></fieldset></dl></div>
                    <legend id='NAZgI'><style id='NAZgI'><dir id='NAZgI'><q id='NAZgI'></q></dir></style></legend>
                  2. <small id='NAZgI'></small><noframes id='NAZgI'>

                    <tfoot id='NAZgI'></tfoot>
                    • <bdo id='NAZgI'></bdo><ul id='NAZgI'></ul>