pytest-check icon indicating copy to clipboard operation
pytest-check copied to clipboard

When the check is placed in the parent step and the child step asserts, the check becomes invalid.

Open Faerie1999 opened this issue 1 year ago • 3 comments

@check.check_func
def validate_something(a, b, c, d):
    with allure.step(f'some assertions'):
        with allure.step('aa'):
            assert a == 1
        with allure.step('b'):
            assert b == 2
        with allure.step('cccc'):
            assert c == 13
        with allure.step('dddd'):
            assert d == 4


def test_22():
    with check, allure.step("setup step"):
        assert 5 == 5
    validate_something(1,2,3,4)

or

def validate_something(a, b, c, d):
    with check, allure.step(f'some assertions'):
        with allure.step('aa'):
            assert a == 1
        with allure.step('b'):
            assert b == 2
        with allure.step('cccc'):
            assert c == 13
        with allure.step('dddd'):
            assert d == 4

run the code, the step dddd won't executed , just as below: image

Faerie1999 avatar Jul 15 '24 10:07 Faerie1999

I think this is in line with the design expectations. If your check point are not interdependent. , your code should be follow:

def validate_something(a, b, c, d):
    with allure.step(f'some assertions'):
        with check, allure.step('aa'):
            assert a == 1
        with check, allure.step('b'):
            assert b == 2
        with check, allure.step('cccc'):
            assert c == 13
        with check, allure.step('dddd'):
            assert d == 4

lanbaoshen avatar Jul 31 '24 01:07 lanbaoshen

I think this is in line with the design expectations. If your check point are not interdependent. , your code should be follow:

def validate_something(a, b, c, d):
    with allure.step(f'some assertions'):
        with check, allure.step('aa'):
            assert a == 1
        with check, allure.step('b'):
            assert b == 2
        with check, allure.step('cccc'):
            assert c == 13
        with check, allure.step('dddd'):
            assert d == 4

I have indeed done this before. if run, the step [some assertions] won't be marked as failed, but passed, and the four sub-steps will be executed, I hope if any sub step is failed, the parent should be marked as failed, and all sub-steps should be executed:

def validate_something(a, b, c, d):
    with allure.step(f'some assertions'):
        with check, allure.step('aa'):
            assert a == 1
        with check, allure.step('b'):
            assert b == 2
        with check, allure.step('cccc'):
            assert c == 13
        with check, allure.step('dddd'):
            assert d == 4


def test_22():
    with check, allure.step("setup step"):
        assert 5 == 5
    validate_something(1,2,3,4)

you can see more in https://github.com/allure-framework/allure-python/issues/824

Faerie1999 avatar Jul 31 '24 01:07 Faerie1999

I'd consider this a feature request, to support allure.step() in conjunction with check.

I would look at a PR for this, but since I don't use allure, I don't have plans to work on this. I'd also want any changes to not affect performance negatively.

okken avatar Aug 27 '24 15:08 okken

I believe pytest-check is behaving correctly.

However, a couple things are getting in the way of allure-pytest and pytest-check working together well in this scenario.

  1. The way allure.step is checking for success/failure is by catching exceptions, and happens with in the test proper.
  2. The way in pytest-check indicates to pytest that a set of checks have at least one failure in it
    • is NOT by raising an exception
    • doesn't happen until right before test teardown, outside of the test proper, after the allure.steps are completed.

Given this, I don't think there even is a way make this work the way you want it to, short of creating a check-like plugin on top of allure-pytest.

In any case, I don't think this is possible from within pytest-check.

okken avatar Mar 30 '25 04:03 okken