Viki-Y
Viki-Y

Reputation: 43

Can assert in pytest have third state - not Fail, not Success, but something as warning or 'weak' fail?

I have items in stock from different companies. And I do not know how to deal if numberOfItems == 0

If I do assert numberOfItems > 0 Then if there is no item in stock it fails.

However I do not want it to fail instead show warning - this can be problem or not, but should not be showstopper for deployment lets say.

Not black/white but grey result of assert.

Upvotes: 4

Views: 2495

Answers (2)

Zim
Zim

Reputation: 515

Probably the best way is to pass it to the log as a warning. Unless you change your logging, these will show up in the output.

Assuming you have logging setup in your conftest:

import logging

log = logging.getLogger(__name__)

def test_your_code():
    # other test code
    if numberOfItems == 0:
        log.warning("No items in stock for this company")

Otherwise, if you need it to be louder, use skip.

import pytest

def test_your_code():
    # other test code
    if numberOfItems == 0:
        pytest.skip("No items in stock for this company")

Upvotes: 0

Brian Booth
Brian Booth

Reputation: 101

I do not know if this is what you are looking for, but it helped me in a similar situation:

if numberOfItems == 0:
     pytest.skip("No items found")

There will be an output which is not PASSED, but it does not fail the run.

Upvotes: 1

Related Questions