-1

I have a class which i expect an index error from and i would like to test it.

I have tried the below, but does not seem to work:

input_data = []
my_class = StudentGrades()
result = my_class.calculate_score(input_data)
assert(IndexError, result)

I would appreciate any assistance on this.

StackUser
  • 425
  • 1
  • 3
  • 12

1 Answers1

0

I assume you're using pytest since you tagged it.

Use pytest.raises:

with pytest.raises(IndexError):
    my_class.calculate_score(input_data)
qcoumes
  • 505
  • 4
  • 13