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

Failed assumption plus error in setup causes subsequent test to appear to fail

Open mikemoerk opened this issue 5 years ago • 2 comments

If a fixture has an assumption failure and an error, then the assumption failure is not cleared, and it will look like the subsequent test failed with that assumption failure.

I am working on a fix and will have a PR soon.

To reproduce, use the following pytest code:

import pytest
@pytest.fixture
def fix():
    pytest.assume(5 == 6, "I live in assume.py::fix fixture")
    raise Exception('oops in setup')

def test_assume(fix):
    pytest.assume(3 == 4, "I live in assume.py::test_assume")

def test_assume3():
        pass

Result is that both tests appear to fail. test_assume fails with the Exception, and test_assume3 fails with test_assume's failed assumption:

pytest test_assume_example.py
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.4, py-1.8.0, pluggy-0.13.0
rootdir: /vagrant/git/dcs_tests/pytest
plugins: assume-2.2.0
collected 2 items

test_assume_example.py EF                                                [100%]

==================================== ERRORS ====================================
________________________ ERROR at setup of test_assume _________________________

    @pytest.fixture
    def fix():
        pytest.assume(5 == 6, "I live in assume.py::fix fixture")
>       raise Exception('oops in setup')
E       Exception: oops in setup

test_assume_example.py:5: Exception
=================================== FAILURES ===================================
_________________________________ test_assume3 _________________________________

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption:
E               1 Failed Assumptions:
E
E               test_assume_example.py:4: AssumptionFailure
E               >>      pytest.assume(5 == 6, "I live in assume.py::fix fixture")
E               AssertionError: I live in assume.py::fix fixture
E               assert False

/usr/local/lib/python3.6/dist-packages/six.py:692: FailedAssumption
========================== 1 failed, 1 error in 0.27s ==========================

mikemoerk avatar Feb 07 '20 21:02 mikemoerk

Thanks for the report & PR! I'll get around to reviewing it shortly.

astraw38 avatar Feb 09 '20 01:02 astraw38

Thanks, Ashley!

mikemoerk avatar Feb 10 '20 16:02 mikemoerk