16

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 (e.g. 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?

  • It's possible but there is no direct option for it. Do you want to do this on module or test class level? ("... test or test class level" does not fully parse for me) – hpk42 Sep 13 '12 at 09:48
  • Yes, first of all on test class level. But it would be great if it was possible for particular test case: e.g. "skip test_B if test_A failed", or even something like "test_A required for test_B"... – Stanislaw Bobritsky Sep 13 '12 at 12:09
  • Possible duplicate of [Pytest: how to skip the rest of tests in the class if one has failed?](http://stackoverflow.com/questions/12411431/pytest-how-to-skip-the-rest-of-tests-in-the-class-if-one-has-failed) – user7610 Jul 30 '16 at 09:49

2 Answers2

5

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.

JamesThomasMoon
  • 6,169
  • 7
  • 37
  • 63
azmeuk
  • 4,026
  • 3
  • 37
  • 64
2

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...
Roy Shilkrot
  • 3,079
  • 29
  • 25