0

I want to execute a single test that is dependent on another test. Let's say for the purpose of the question I have the following tests and one of them is depending on another test. I am using pytest-dependency.

class TestClass:

    @pytest.mark.dependency()
    def test_one(self):
        pass

    @pytest.mark.dependency(depends=["TestClass::test_one"])
    def test_two(self):
        pass

When I run the whole suite everything is working perfectly, but when I try to execute only the test test_one it always skips because the first test is not passed. Shouldn't the first test be executed in this case too?

Gabriel kotev
  • 369
  • 3
  • 15
  • Because you're using the same name for the two tests? – Ashwini Chaudhary Nov 10 '21 at 10:20
  • This is a bad design, tests should not depend on each other, use fixtures for this purpose – dosas Nov 10 '21 at 10:47
  • @PhilippSelenium Could not agree more, but I have a case where every operation takes around 15 min and when you need to write a couple of tests it goes up to an hour. Also, it is not possible to add this operation inside a fixture, because there are other tests that rely on the fact that this operation is not executed. – Gabriel kotev Nov 10 '21 at 11:53
  • What about fixture scoping? – dosas Nov 10 '21 at 13:12
  • With `pytest-dependency` this will not work due to its design. I have not tried [pytest-depends](https://pypi.org/project/pytest-depends/) which has a similar goal - maybe it will behave differently. – MrBean Bremen Nov 10 '21 at 21:24

0 Answers0