Opened 10 years ago

Closed 8 years ago

#23943 closed Cleanup/optimization (fixed)

Audit tests decorated with unittest.expectedFailure

Reported by: Tim Graham Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: diegaogs@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


There are less than 10 tests in our test suite that use @unittest.expectedFailure. We should check to make sure these tests are still valid.

  1. Does the test still fail? If not, remove the decorator.
  2. Is there a plan/ticket to fix the issue? If so, add a comment with the ticket number with the and make sure the test is linked to in the ticket. If not, create a ticket for the issue.

Change History (4)

comment:1 by Marc Tamlyn, 10 years ago

1 is a moot point - an expected failure test is run, and is reported as an "unexpected success" if it passes. In python 3.4 at least I think this is considered the same as a fail.

I have used expected failure a few times in the postgres array tests where I expect a query to fail with a database error. If this starts passing, I'd like to know about it and update the documentation. I could catch and inspect the error instead, but I feel saying "run this and I expect it to fail" is better than "run this and expect a given error from outside our code" - I'd use assertRaises to check my own raise statements only.

I don't mind if this is changed (or at least more clearly commented).

comment:2 by Diego Guimarães, 10 years ago

Cc: diegaogs@… added

While crossing references on those tests with the @expectedFailure decorator, this one seems that do not pass the audit tests/generic_views/

    def test_update_put(self):
        a = Author.objects.create(
            name='Randall Munroe',
        res = self.client.get('/edit/author/%d/update/' %
        self.assertEqual(res.status_code, 200)
        self.assertTemplateUsed(res, 'generic_views/author_form.html')

        res = self.client.put('/edit/author/%d/update/' %,
                        {'name': 'Randall Munroe (author of xkcd)', 'slug': 'randall-munroe'})
        # Here is the expected failure. PUT data are not processed in any special
        # way by django. So the request will equal to a POST without data, hence
        # the form will be invalid and redisplayed with errors (status code 200).
        # See also #12635
        self.assertEqual(res.status_code, 302)
        self.assertRedirects(res, 'http://testserver/list/authors/')
        self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (author of xkcd)>'])

This test is related to ticket #12635 marked as wontfix, and according to the last comment on that, Using PUT and DELETE as HTTP methods for the form element is no longer supported (

Last edited 10 years ago by Diego Guimarães (previous) (diff)

comment:3 by Tim Graham <timograham@…>, 10 years ago

In df9f2e41fae68e2079db61e07569fdc89d1d6343:

Refs #23943 -- Removed an invalid generic_views test.

Using PUT as a method for the form element is no longer supported
as described in the ticket.

comment:4 by Tim Graham, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top