I'm in favor of the second version because the first one hides the stack trace.

`self.fail` is almost always the wrong answer, because the actual failure 
happened earlier in the test!

I usually include a comment like "# this should not raise an exception" in such 
tests to explain why they don't contain assertions.

-- 
Aymeric.



On 8 juil. 2013, at 22:55, Shai Berger <[email protected]> wrote:

> Hi all,
> 
> I just pushed a fix to a test failure on Oracle -- the last-executed-query 
> test. However, I want to ask about the preferred style in writing the test 
> itself. The test, as it is written now, is:
> 
>    def test_last_executed_query(self):
>        """
>        last_executed_query should not raise an exception even if no previous
>        query has been run.
>        """
>        cursor = connection.cursor()
>        try:
>            connection.ops.last_executed_query(cursor, '', ())
>        except Exception:
>            self.fail("'last_executed_query' should not raise an exception.")
> 
> I find that "try..except" distasteful: if the test is written simply as
> 
>    def test_last_executed_query(self):
>        """
>        last_executed_query should not raise an exception even if no previous
>        query has been run.
>        """
>        cursor = connection.cursor()
>        connection.ops.last_executed_query(cursor, '', ())
> 
> then it checks exactly the same thing, but when it fails, it prints the 
> exception instead of just saying there was one -- which is much more useful. 
> The only downside I see is, this is reported as an Error rather than a 
> Failure; but personally, I don't think that matters.
> 
> Comments? Any reason not to change it?
> 
> Thanks,
>       Shai.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-developers.
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to