uber/doubles

Tests should fail if a any Doubles Exception is raised

Opened this issue · 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?

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

@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.

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

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.