Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[py.test]: test dependencies

Tags:

python

pytest

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?

like image 510
Stanislaw Bobritsky Avatar asked Sep 12 '12 14:09

Stanislaw Bobritsky


People also ask

What are dependencies in test cases?

Dependency Testing, a testing technique in which an application's requirements are pre-examined for an existing software, initial states in order to test the proper functionality.

Where do I put Pytests?

While the pytest discovery mechanism can find tests anywhere, pytests must be placed into separate directories from the product code packages. These directories may either be under the project root or under the Python package.

Do you have to import pytest?

The conftest.py file serves as a means of providing fixtures for an entire directory. Fixtures defined in a conftest.py can be used by any test in that package without needing to import them (pytest will automatically discover them).


1 Answers

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.

like image 173
azmeuk Avatar answered Oct 10 '22 20:10

azmeuk