doubles icon indicating copy to clipboard operation
doubles copied to clipboard

Tests should fail if a any Doubles Exception is raised

Open toddsifleet opened this issue 10 years ago • 4 comments

Even if a Doubles exception is caught within the test we should still fail the test.

I just ran into this issue changing a call signature, I missed a spot but the UnallowedMethodCallError was caught so the test passed (I am refactoring the tests :)).

@breerly @blampe @charlax any thoughts?

toddsifleet avatar Sep 15 '15 15:09 toddsifleet

Do you have a concrete code example? Not sure to understand :)

charlax avatar Sep 15 '15 16:09 charlax

@charlax here is an example:

import my_module

def my_code_under_test():
    my_module.some_method(2)

def test_my_code():
    allow(my_module).some_method.with_args(1).and_raise(Exception('Foobar'))
    with pytest.raises(Exception):
        my_code_under_test()

This test would pass but should clearly fail because my_module.some_method is called with 2 not 1 as allowed. But the doubles.exceptions.UnallowedMethodCallError is caught by the context manager.

I understand that this test should be more specific, but I think this is something doubles could/should catch.

toddsifleet avatar Sep 15 '15 16:09 toddsifleet

How would doubles catch that? It can't control whether the caller is catching a reasonable exception. This is just a bad test IMO.

blampe avatar Sep 15 '15 17:09 blampe

Doubles would not catch the exception, it would keep track that the UnallowedMethodCallError (or any doubles exception) was raised and then fail the test during cleanup.

toddsifleet avatar Sep 15 '15 17:09 toddsifleet