Test Exception Raising
Write a function divide(a, b) that raises a ValueError when b is 0, then write a test that confirms the exception is actually raised — following pytest.raises()'s pattern using a plain try/except.
Approach: implement divide(a, b) to raise ValueError("Cannot divide by zero") when b == 0. Then call it inside a try block; if the ValueError is caught, the test passed.
Input: Two lines: a, then b (b will be 0).
Output: One line: Test passed: ValueError raised as expected (or FAIL: no exception raised if divide() doesn't raise correctly).
10 0
Test passed: ValueError raised as expected
- b is always 0 in this problem.
Hint 1
raise ValueError("...") inside divide() is what pytest.raises(ValueError) would be checking for.
Hint 2
The try/except here plays the same role pytest.raises() plays — catching the expected exception and confirming it happened.
Hint 3
If divide() returns normally instead of raising, the test correctly reports FAIL.
divide(a, b) raises ValueError("Cannot divide by zero") whenever b is 0. The surrounding try/except plays the role of pytest.raises(ValueError): if the exception fires, the except block confirms the test passed; if divide() somehow returns normally, the code right after the call prints the FAIL message instead.