uber / doubles

Test doubles for Python.
MIT License
164 stars 17 forks source link

Tests should fail if a any Doubles Exception is raised #89

Open toddsifleet opened 9 years ago

toddsifleet commented 9 years ago

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?

charlax commented 9 years ago

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

toddsifleet commented 9 years ago

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

blampe commented 9 years ago

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

toddsifleet commented 9 years ago

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.