Tests should fail if a any Doubles Exception is raised
Opened this issue · 4 comments
toddsifleet commented
charlax commented
Do you have a concrete code example? Not sure to understand :)
toddsifleet commented
@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
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
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.