PyTest expected exceptions (bank deposit) - no exception happens
Pytest properly reports that there was no exception where an exception was expected.
examples/pytest/b2/banks.py
class NegativeDeposite(Exception): pass class Bank: def __init__(self, start): self.balance = start def deposit(self, money): #if money < 0: # raise NegativeDeposite('Cannot deposit negative sum') self.balance += money return
examples/pytest/b2/error.txt
def test_negative_deposit(): b = Bank(10) with pytest.raises(NegativeDeposite) as e: > b.deposit(-1) E Failed: DID NOT RAISE <class 'Exception'>