Hi Shai,
On 07/08/2013 02:55 PM, Shai Berger wrote:
> 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.
I don't find much value in the E/F distinction either; I think the
important thing is to provide output when the test fails that helps to
clarify why it failed. There are cases where catching an exception and
explicitly failing allows you to provide useful contextual info instead
of an exception whose meaning may be unclear. In this case it seems like
the opposite: the specific exception, which may be useful, is
suppressed, and no additional info is provided beyond "some exception
was raised". So personally I would be fine with removing the try/except
here.
I generally prefer it if the test asserts _something_ though; the
seemingly obvious candidate here would be, what's the return value of
last_executed_query when no previous query has been run? Is it not
consistent?
Carl
--
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.