Pytest and ValueError and ZeroDivisionError

I was wondering if someone could help. Why is pytest not raising an ValueError or a ZeroDivisionError? Thank you. Stephen

def main():
    while True:
        message = input("Fraction: ")
        my_percent = convert(message)

        answer = gauge(my_percent)
        print(answer)


def convert(fraction):
    my_number = fraction.split("/")
    try:
        fraction = int(my_number[0])/int(my_number[1])
    except ValueError:
        pass
    except ZeroDivisionError:
        pass
    else:
        percent = int((fraction*100))
        return percent


def gauge(percentage):
    if percentage <= 1:
        return "E"
    elif percentage >= 99:
        return "F"
    else:
        return f"{percentage}%"


if __name__ == "__main__":
    main()
from fuel import convert, gauge
import pytest


def test_integer():
    assert convert('1/4') == 25
    assert convert('0/4') == 0
    assert convert('4/4') == 100

def test_convert():
    with pytest.raises(ZeroDivisionError):
        convert('100/0')

def test_valid_type():
    with pytest.raises(ValueError):
        convert('three/four')


def test_gauge():
    assert gauge(.75) == 'E'
    assert gauge(1) == 'E'
    assert gauge(100) == 'F'
    assert gauge(99) == 'F'
    assert gauge(45) == '45%'
    assert gauge(105) == 'F'
    assert gauge(0) == 'E'

Your convert() function explicitly catches and discards ValueError and ZeroDivisionError. Is there a reason for that?

Since the function doesn’t throw those errors, pytest won’t see them. It’s not that pytest isn’t raising it. It’s that when pytest is calling your function, it’s reporting that your function didn’t raise it.

If you get rid of the entire try/except block in fuel.py and just have the fraction, percent, and return lines, the pytest will pass.

Thank you so much !