Git Product home page Git Product logo

Comments (5)

RKrahl avatar RKrahl commented on May 23, 2024

Trying to boil down your setting to a minimal example, I believe you are trying to do something like this:

import pytest

@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_a():
    assert False

@pytest.mark.dependency()
def test_b():
    pass

@pytest.mark.dependency(depends=["test_a"])
@pytest.mark.dependency(depends=["test_b"])
def test_c(request):
    pass

Indeed, if you try this, test_c will not be skipped, even though test_a fails. In fact, using multiple pytest.mark.dependency markers for a single test simply does not work. The dependencies in the markers will not be combined, but the dependencies from the second marker will override those from the first. That is why the dependency on test_a will simply be ignored. This seem to be consistent with what you describe in your setting. The simple example must be rewritten as follows to work:

import pytest

@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_a():
    assert False

@pytest.mark.dependency()
def test_b():
    pass

@pytest.mark.dependency(depends=["test_a", "test_b"])
def test_c(request):
    pass

In your setting, you might want to try something like the following:

@pytest.mark.dependency(
    depends=instances(

            "tests/test_xyz.py::TestThis::test_that",
            params_this,
        ) + instances(

            "tests/test_xyz.py::TestThis::test_this_as_well",
            params_that,
        ),
    scope="session",
)
class TestEverything:
    """Class to test everything."""

from pytest-dependency.

anishradvani avatar anishradvani commented on May 23, 2024

Hey @RKrahl thanks for your response. Appreciate the work you have done on this package. I did try the exact setting you suggested, but I find any combination of it skips all the tests in the dependency marker.

I do not have the @pytest.mark.xfail marker on the test class that needs to pass, but I don't think that should matter.

tests/test_steady_state.py::TestThis::test_that[a] PASSED                                 
tests/test_steady_state.py::TestThis::test_that[b] PASSED                                 
tests/test_steady_state.py::TestThis::test_that[c] PASSED                                 
tests/test_steady_state.py::TestThis::test_that[d] PASSED                                  
tests/test_steady_state.py::TestThis::test_that[e] PASSED                                  
tests/test_steady_state.py::TestThis::test_this_as_well[a] PASSED                          
tests/test_steady_state.py::TestThis::test_this_as_well[b] PASSED                          
tests/test_steady_state.py::TestThis::test_this_as_well[c] PASSED                          
tests/test_steady_state.py::TestThis::test_this_as_well[d] PASSED                           
tests/test_steady_state.py::TestThis::test_this_as_well[e] PASSED                           
tests/test_all.py::TestEverything::test_pre[test_content0-xyz] SKIPPED                                                                       
tests/test_all.py::TestEverything::test_body[test_content0-xyz] SKIPPED                                                                       
tests/test_all.py::TestEverything::test_post[test_content0-xyz] SKIPPED                                                                       
tests/test_all.py::TestEverything::test_pre[test_content1-xyz] SKIPPED                                                                           
tests/test_all.py::TestEverything::test_body[test_content1-xyz] SKIPPED                                                                           
tests/test_all.py::TestEverything::test_post[test_content1-xyz] SKIPPED  

Is this something you're able to replicate? I have the same "session" scope in my dependency settings as well.

from pytest-dependency.

anishradvani avatar anishradvani commented on May 23, 2024

Also, it would be great to be able to have pytest-dependency run based on a class dependency rather than a method, for example

@pytest.mark.dependency(
    depends=instances(

            "tests/test_xyz.py::TestThis",
            params_this,
    scope="session",
)
class TestEverything:
    """Class to test everything."""

from pytest-dependency.

RKrahl avatar RKrahl commented on May 23, 2024

@anishradvani, I'm sorry, I'm not able to debug your code. First of all, I can't do this because you posted only fragments of it by now, so I don't have the full picture. But even if you had posted your full code, I can't do this simply because I don't have the time to do your home work.

If you believe to see some behavior that hints on a bug in pytest-dependency, I have to ask you to create a minimal example (in the same manner as I did above) of code that reproduces the alleged bug.

Regarding your last comment: actually this works, see #39.

from pytest-dependency.

RKrahl avatar RKrahl commented on May 23, 2024

This issue originally was about that multiple dependency markers for a single test does not work. Actually this was never supposed to work. I'll therefore close as invalid.

from pytest-dependency.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.