Skip to content
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

Remove parametrization when storing dependency results #43

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

DevilXD
Copy link

@DevilXD DevilXD commented Jun 7, 2020

Utilizing the same approach as in #33, but up to date and more efficient. This closes #9.

EDIT: Forgot to add that I replaced setdefault with that if statement there on purpose, because that's more efficient than constructing an instance of DependencyitemStatus() and then discarding it every time that line runs. Ref: https://stackoverflow.com/questions/22797251/why-does-setdefault-evaluate-default-when-key-is-set

@GalOzRlz
Copy link

Can this please be merged? :(

@RKrahl
Copy link
Owner

RKrahl commented Jan 8, 2022

Many thanks for your contribution and please apologize for the very late reply! I needed some time to really look into this and didn't got around to do that earlier.

Unfortunately, your change breaks documented use cases. Please note that this is not just another artificial example for the documentation. It is modeled after a real application that is used in production.

I can also provide an even simpler example to demonstrate the problem. Consider:

import pytest

@pytest.mark.parametrize("x", [
    pytest.param(0),
    pytest.param(1, marks=pytest.mark.xfail(reason="deliberate fail")),
])
@pytest.mark.dependency()
def test_a(x):
    assert x == 0

@pytest.mark.parametrize("x", [
    pytest.param(0, marks=pytest.mark.dependency(depends=["test_a[0]"])),
    pytest.param(1, marks=pytest.mark.dependency(depends=["test_a[1]"])),
])
def test_b(x):
    pass

I guess the idea is obvious: test_b for any parameter value should depend on test_a for the same parameter value. If you run this using the last release version of pytest-dependency, it works as expected:

$  python -m pytest --verbose test_params.py 
============================= test session starts ==============================
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /home/abuild/test
plugins: dependency-0.5.1
collected 4 items                                                              

test_params.py::test_a[0] PASSED                                         [ 25%]
test_params.py::test_a[1] XFAIL (deliberate fail)                        [ 50%]
test_params.py::test_b[0] PASSED                                         [ 75%]
test_params.py::test_b[1] SKIPPED (test_b[1] depends on test_a[1])       [100%]

=================== 2 passed, 1 skipped, 1 xfailed in 0.03s ====================

test_a[1] fails and thus test_b[1] is skipped.

When I run the same example with your version, I get:

$  python -m pytest --verbose test_params.py 
============================= test session starts ==============================
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/bin/python
cachedir: .pytest_cache
rootdir: /home/abuild/test
plugins: dependency-0.5.2.dev16+g0881560
collected 4 items                                                              

test_params.py::test_a[0] PASSED                                         [ 25%]
test_params.py::test_a[1] XFAIL (deliberate fail)                        [ 50%]
test_params.py::test_b[0] SKIPPED (test_b[0] depends on test_a[0])       [ 75%]
test_params.py::test_b[1] SKIPPED (test_b[1] depends on test_a[1])       [100%]

=================== 1 passed, 2 skipped, 1 xfailed in 0.03s ====================

Now, also test_b[0] is skipped, although its dependency test_a[0] had succeeded. This is not what we want.

The ability to distinguish in the dependencies the individual instances for different parameter values of a test is an important feature of pytest-dependency that must be preserved.

@DevilXD
Copy link
Author

DevilXD commented Jan 8, 2022

Is it better now?

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

Successfully merging this pull request may close these issues.

Add a helper to return the names of parametrized test instances
3 participants