Reputation: 43
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
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
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