unittest: assertRaises() with an instance instead of a type
Ethan Furman
ethan at stoneleaf.us
Fri Mar 30 13:45:39 EDT 2012
Steven D'Aprano wrote:
> To the degree that the decision of how finely to slice tests is a matter
> of personal judgement and/or taste, I was wrong to say "that is not the
> right way". I should have said "that is not how I would do that test".
>
> I believe that a single test is too coarse, and three or more tests is
> too fine, but two tests is just right. Let me explain how I come to that
> judgement.
>
> If you take a test-driven development approach, the right way to test
> this is to write testFooWillFail once you decide that foo() should raise
> MyException but before foo() actually does so. You would write the test,
> the test would fail, and you would fix foo() to ensure it raises the
> exception. Then you leave the now passing test in place to detect
> regressions.
>
> Then you do the same for the errorcode. Hence two tests.
[snip]
> So: never remove tests just because they are redundant. Only remove them
> when they are obsolete due to changes in the code being tested.
Very persuasive argument -- I now find myself disposed to writing two
tests (not three, nor five ;).
~Ethan~
More information about the Python-list
mailing list