简体   繁体   中英

[py.test]: test dependencies

I'm writing test system using py.test, and looking for a way to make particular tests execution depending on some other test run results.

For example, we have standard test class:

import pytest

class Test_Smoke:
   def test_A(self):
       pass

   def test_B(self):
       pass

   def test_C(self):
       pass

test_C() should be executed if test_A() and test_B() were passed, else - skipped.

I need a way to do something like this on test or test class level (eg Test_Perfo executes, if all of Test_Smoke passed), and I'm unable to find a solution using standard methods (like @pytest.mark.skipif).

Is it possible at all with pytest?

You might want to have a look at pytest-dependency . It is a plugin that allows you to skip some tests if some other test had failed.

Consider also pytest-depends :

def test_build_exists():
    assert os.path.exists(BUILD_PATH)

@pytest.mark.depends(on=['test_build_exists'])
def test_build_version():
    # this will skip if `test_build_exists` fails...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM