Comments (2)
This is not supported out of the box. But you can implement it using a small helper function:
import pytest
from pytest_dependency import depends
def depends_or(request, other, scope='module'):
"""Add dependency on any of the other tests.
Call pytest.skip() unless a successful outcome of any of the tests
in `other` has been registered previously. This helper is similar
to `pytest_dependency.depends()`. It takes the same arguments.
But while `pytest_dependency.depends()` combines the tests in
`other` in an and-like manner, it skips the current test unless
all other tests did succeed, this function combines them in an
or-like manner, it runs the current test if at least one of the
other tests did succeed.
"""
item = request.node
for o in other:
try:
depends(request, [o], scope)
except pytest.skip.Exception:
continue
else:
return
pytest.skip("%s depends on any of %s" % (item.name, ", ".join(other)))
@pytest.mark.dependency()
def test_ap():
pass
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_ax():
assert False
@pytest.mark.dependency()
def test_bp():
pass
@pytest.mark.dependency()
@pytest.mark.xfail(reason="deliberate fail")
def test_bx():
assert False
@pytest.mark.dependency()
def test_c(request):
depends_or(request, ["test_ax", "test_bx"])
pass
@pytest.mark.dependency()
def test_d(request):
depends_or(request, ["test_ax", "test_bp"])
pass
@pytest.mark.dependency()
def test_e(request):
depends_or(request, ["test_ap", "test_bx"])
pass
@pytest.mark.dependency()
def test_f(request):
depends_or(request, ["test_ap", "test_bp"])
pass
Tests test_c
, test_d
, test_e
, and test_f
all depend on either test_a
or test_b
in the manner you described. I included succeeding and failing incarnations of test_a
and test_b
to demonstrate the effect. Only test_c
will be skipped, because both tests in its dependency list fail, the other ones are run, because they have at least on succeeding test in their dependency list.
Warning: as usual, the documentation of internal data structures in pytest is scarce. It is not documented at all that skipping of tests internally work by raising a Skipped
exception and this exception class is exposed in the pytest.skip.Exception
attribute of pytest.skip()
. As usual I needed to find out by reading the pytest source code. There is thus no guarantee that this is stable across pytest versions and I did not check whether it works with all versions supported by pytest-dependency.
from pytest-dependency.
Great, will try it out. Thank you
from pytest-dependency.
Related Issues (20)
- Test suite incompatibility with pytest 6.2 HOT 2
- Tests skipped on linux(3.6.13)(with no test failed) but executing on windows(3.6.10) HOT 3
- Dependency between two tests HOT 1
- session scope not working HOT 1
- Depends on all test methods in class HOT 1
- 0.5.1: pytest is failing HOT 4
- Is ordering on fixtures supported?
- only test_b is passed when install pytest-xdist with n>2.
- Not skipping a test when parent test skips or xfails
- The test was skipped,although the dependency test is success. HOT 5
- Dependency call is skipped by executing test with mark HOT 3
- pytest dependency not skipping the dependent tests when failed HOT 3
- when the dependency case use @pytest.mark.parametrize, depened cases was skipped,although the dependency test is success HOT 1
- is @pytest.mark.dependency() can be used for class level? like API test class depends on BVT test class...
- pyproject.toml missing
- Inheriting from test class with dependencies doesn't work correctly HOT 1
- Is pytest-dependency suppose to tell me why a test was skipped? I see nothing in the output explaining why. HOT 1
- Rerunning skipped cases when the parent test fails
- 0.6.0: pep517 based build fails with `Invalid version: 'UNKNOWN'` error message HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-dependency.