Skip to content

Dependency between tests #2317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ramnes opened this issue Mar 17, 2017 · 10 comments
Closed

Dependency between tests #2317

ramnes opened this issue Mar 17, 2017 · 10 comments

Comments

@ramnes
Copy link

ramnes commented Mar 17, 2017

Is there any way currently to declare some dependency between tests?

In an ideal world, I'd love something like this:

import pytest

def test_foo():
    assert False

def test_bar():
    assert True

@pytest.depends_on(test_foo, test_bar)
def test_baz():
    pass

Where test_baz would fail because at least one of test it depends on failed (test_foo).

If that doesn't exist yet, would you think it could be a pytest feature? Or a good purpose for a plugin?

@RonnyPfannschmidt
Copy link
Member

currently its not supported, but its a mechanism thats often needed for system level testing in order to safe time

its really hard to do a feature like this properly atm, because we would need to integrate with parameterization and test items correctly - internal refactoring are needed to give this a solid base

as for expressing it, my proposal for the initial prototype would be

import pytest

def test_foo():
    assert False

def test_bar():
    assert True

@pytest.mark.test_depends_on(test_foo, test_bar)
def test_baz():
    pass

@BlacKCaT27
Copy link

Has there been any movement or work put into making this feature a reality? It'd be extremely helpful for integration/system level testing like you commented before.

@nicoddemus
Copy link
Member

@BlacKCaT27 I don't think anybody is working on this.

A workaround I suggest is to name the test functions differently and call them from a proper test. For example:

import pytest

def check_foo():
    assert False

def check_bar():
    assert True

def test_baz():
    check_foo()
    check_bar()

@BlacKCaT27
Copy link

Thanks for the rapid reply. That's a great workaround I'll be sure to use.

Also, could you confirm something for me? I've noticed (and seen others online mention) that pytest appears to run all tests in a module from top to bottom by default. Is that guaranteed behavior or just a happenstance of how pytest currently discovers tests from a module?

@RonnyPfannschmidt
Copy link
Member

py.test tries to order based on source location ,but will reshuffle based on fixture scope to avoid unnecessary setup/teardown,

@BlacKCaT27
Copy link

BlacKCaT27 commented Jul 24, 2017 via email

@The-Compiler
Copy link
Member

FWIW there's also the pytest-ordering plugin.

@somnambWl
Copy link

somnambWl commented Aug 3, 2017

There is a package pytest-dependency that does exactly what you/we want.

@nicoddemus
Copy link
Member

Should we close this? So far we have one workaround and two plugins; IMHO we don't need to integrate this into the core.

@ramnes
Copy link
Author

ramnes commented Aug 3, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants