Getting some Unit Testing done in python

  Kiến thức lập trình

The problem was:

Convert: Takes a string input in the form “X/Y” where X and Y are integers, computes the percentage X/Y * 100 rounded to the nearest
integer, and handles errors such as division by zero or non-integer
inputs.

Gauge: Takes an integer percentage and returns: “E” if the percentage is 1 or less. “F” if the percentage is 99 or more.
Otherwise, it should return the percentage followed by “%”.

And write a test file using pytest.

my main file code

heres the test case code:

My test code is correct, but whenever I ran it, the test case where we check the errors raised was giving errors. with “pytest.raises(ValueError): convert(“dog/cat”)”

It seems try catch needed to be executed twice. Can someone enlighten me for a better way?

heres the correct main file code for reference :

New contributor

Hardik Katyal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT