Reputation: 25
I am running into an issue with a basic negative unit test. Attempting to successfully expect a NotFoundException error within the last function. The issue I am running into is that the stack catches the error first and completely nullifies that expect() function. Please help, TIA.
‘’’
def test_should_return_coffee_not_found(
coffee_information_repository_mock, coffee_information, coffee_drink
):
coffee_information_repository_mock.get_coffee_information.return_value = (
coffee_information
)
coffee_information_service = CoffeeInformationService(
coffee_information_repository_mock
)
result = coffee_information_service.get_drink_by_title("Gatorade")
expect(result).to(raise_error(NotFoundException))
‘’’
Upvotes: 0
Views: 118
Reputation: 3162
The raise error matcher for expects requires you to pass a no argument function to expect
. You aren't passing a callback to expect, but invoking the function you want to test. The easiest way to do this is with a lambda
expect(lambda: coffee_information_service.get_drink_by_title("Gatorade")).to(raise_error(NotFoundException))
Upvotes: 1