Pytest: How to set test in one file to be skipped if test from another file fails

641 views Asked by At

I need to organize my test cases because I have a large test suite. I can't see to get a test in one Python class to be skipped if a test it depends on in another Python class fails.

Here is my basic setup:

class TestWorkflow1:

    @staticmethod
    @pytest.mark.dependency()
    def test_create_something():
        //do some stuff    

class TestNegativeWorkflowClone1:

    @staticmethod
    @pytest.mark.dependency('TestWorkflow1::test_create_something')
    def test_try_to_clone_something():
        //do some stuff 

TestNegativeWorkflowClone1 runs before TestWorkflow1. I have tried what was suggested in an answer to this ticket: Dependencies between files with pytest-dependency?

from pytest_dependency import DependencyManager

class TestWorkflow1:
    DependencyManager.ScopeCls['module'] = DependencyManager.ScopeCls['session']

    @staticmethod
    @pytest.mark.dependency()
    def test_create_something():
        //do some stuff    

from pytest_dependency import DependencyManager

class TestNegativeWorkflowClone1:
    DependencyManager.ScopeCls['module'] = DependencyManager.ScopeCls['session']

    @staticmethod
    @pytest.mark.dependency('TestWorkflow1::test_create_something')
    def test_try_to_clone_something():
        //do some stuff 

That didn't work either. TestNegativeWorkflowClone1 still runs before TestWorkflow1.

I tried using the filename in the dependency decoration in TestNegativeWorkflowClone1

class TestNegativeWorkflowClone1:
    DependencyManager.ScopeCls['module'] = DependencyManager.ScopeCls['session']

    @staticmethod
    @pytest.mark.dependency('TestWorkflow1.py::test_create_something')
    def test_try_to_clone_something():
        //do some stuff 

Still didn't work. TestNegativeWorkflowClone1 still runs first.

0

There are 0 answers