[Python/Linked-List] Issue when testing exceptions

linked_list_test.py tests whether the solution raises the right exceptions with the right error message like this:

    def test_can_return_with_pop_and_then_raise_an_error_if_empty(self):
        lst = LinkedList()
        lst.push(1)
        lst.unshift(5)
        self.assertEqual(lst.pop(), 1)
        self.assertEqual(lst.pop(), 5)
        with self.assertRaises(IndexError) as err:
            lst.pop()
            self.assertEqual(type(err.exception), IndexError)
            self.assertEqual(err.exception.args[0], "List is empty")

But the last two lines are inside the with self.assertRaises... block, so they only get executed when lst.pop() does not raise an exception.

I think they should be outside of the block (i.e. the indentation of these two lines should be reduced) so they get executed after an exception has been raised.
That’s how the example in the official documentation does it, and how this answer on StackOverflow explains it.

The same applies to the other test functions that test the error handling.

If it helps I could create a PR but I’m fine if somebody else does it.

1 Like

Hi @siebenschlaefer,

Thanks for brining this up. I am busy today, but will take a look at this a little later my time.

Since this is a templated exercise, I am not interested in a PR unless someone is well-versed in JinJa2, and is willing to do a fair amount of testing and regenerating files - probably best if I do it myself.

1 Like

@BethanyG Friendly reminder: Did you find time yet to take a look at this?

Nope. But will make time between today and tomorrow. :slightly_smiling_face:

1 Like
2 Likes