Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#16574 closed Bug (fixed)

Test fails when setting MESSAGE_TAGS

Reported by: Boldewyn Owned by: elbarto
Component: contrib.messages Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

in a fresh Django 1.3 project (directly after django_admin
startproject) I set this in the settings.py:

MESSAGE_TAGS = {

40: "ui-state-error", # ERROR
30: "ui-state-highlight", # WARNING
20: "ui-state-info", # INFO
25: "ui-state-success", # SUCCESS

}

which causes a test failure in
django.contrib.messages.tests.cookie.CookieTest.test_tags.

http://pastebin.com/DSWdgCEf

As far as I can see, I did everything the way the docs say.

Corresponding list message: http://groups.google.com/group/django-developers/browse_thread/thread/4ab6ef2eedd4bfbe

Attachments (3)

message_tests.diff (727 bytes) - added by elbarto 3 years ago.
16574-2.diff (9.4 KB) - added by claudep 3 years ago.
Generalize override_settings
16574-3.diff (10.3 KB) - added by claudep 3 years ago.
Fix base.LEVEL_TAGS at override_settings level

Download all attachments as: .zip

Change History (15)

comment:1 Changed 4 years ago by aaugustin

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

It should be pretty easy to fix the tests with @override_settings.

comment:2 Changed 4 years ago by elbarto

  • Owner changed from nobody to elbarto

Changed 3 years ago by elbarto

comment:3 Changed 3 years ago by elbarto

With this patch it passes the tests:

bsanchez@bsanchez:~/test/testproject$ python manage.py test messages
Creating test database for alias 'default'...
........................................................................
----------------------------------------------------------------------
Ran 72 tests in 0.478s

OK
Destroying test database for alias 'default'...
bsanchez@bsanchez:~/test/testproject$

On the other hand, I set the decorator in the class instead of the method because it fails there:

bsanchez@bsanchez:~/test/testproject$ python manage.py test messages
Creating test database for alias 'default'...
......................F.................................................
======================================================================
FAIL: test_tags (django.contrib.messages.tests.cookie.CookieTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/bsanchez/src/trunk/django/test/utils.py", line 214, in inner
    return test_func(*args, **kwargs)
  File "/home/bsanchez/src/trunk/django/contrib/messages/tests/base.py", line 372, in test_tags
    'success'])
AssertionError: Lists differ: [u'info', '', u'extra-tag debu... != ['info', '', 'extra-tag debug'...

First differing element 4:
ui-state-error
error

- [u'info', '', u'extra-tag debug', u'warning', u'ui-state-error', u'success']
?  -            -                   -           - ---------        -

+ ['info', '', 'extra-tag debug', 'warning', 'error', 'success']

----------------------------------------------------------------------
Ran 72 tests in 0.467s

FAILED (failures=1)
Destroying test database for alias 'default'...
bsanchez@bsanchez:~/test/testproject$

comment:4 Changed 3 years ago by elbarto

  • Has patch set

Changed 3 years ago by claudep

Generalize override_settings

comment:5 Changed 3 years ago by claudep

Just added a patch that uses override_settings throughout the contrib.messages tests.

comment:6 Changed 3 years ago by julien

  • Patch needs improvement set

Thanks, the patch is generally looking good. However, I'm now getting 3 failures. Am I missing something?

python manage.py test messages
Creating test database for alias 'default'...
......................F..........................F...................F..
======================================================================
FAIL: test_tags (django.contrib.messages.tests.cookie.CookieTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/julien/Documents/Development/eclipse/workspace/DjangoCore/git/django/contrib/messages/tests/base.py", line 339, in test_tags
    'success'])
AssertionError: Lists differ: [u'info', '', u'extra-tag debu... != ['info', '', 'extra-tag debug'...

First differing element 4:
ui-state-error
error

- [u'info', '', u'extra-tag debug', u'warning', u'ui-state-error', u'success']
?  -            -                   -           - ---------        -

+ ['info', '', 'extra-tag debug', 'warning', 'error', 'success']

======================================================================
FAIL: test_tags (django.contrib.messages.tests.fallback.FallbackTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/julien/Documents/Development/eclipse/workspace/DjangoCore/git/django/contrib/messages/tests/base.py", line 339, in test_tags
    'success'])
AssertionError: Lists differ: [u'info', '', u'extra-tag debu... != ['info', '', 'extra-tag debug'...

First differing element 4:
ui-state-error
error

- [u'info', '', u'extra-tag debug', u'warning', u'ui-state-error', u'success']
?  -            -                   -           - ---------        -

+ ['info', '', 'extra-tag debug', 'warning', 'error', 'success']

======================================================================
FAIL: test_tags (django.contrib.messages.tests.session.SessionTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/julien/Documents/Development/eclipse/workspace/DjangoCore/git/django/contrib/messages/tests/base.py", line 339, in test_tags
    'success'])
AssertionError: Lists differ: [u'info', '', u'extra-tag debu... != ['info', '', 'extra-tag debug'...

First differing element 4:
ui-state-error
error

- [u'info', '', u'extra-tag debug', u'warning', u'ui-state-error', u'success']
?  -            -                   -           - ---------        -

+ ['info', '', 'extra-tag debug', 'warning', 'error', 'success']

----------------------------------------------------------------------
Ran 72 tests in 0.937s

FAILED (failures=3)
Destroying test database for alias 'default'...

comment:7 Changed 3 years ago by claudep

Strange... Julien, where does this 'ui-state-error' comes from?

comment:8 Changed 3 years ago by claudep

Sorry, forgot my comment above. Of course, the problem is with base.LEVEL_TAGS. Will work on a new patch.

Changed 3 years ago by claudep

Fix base.LEVEL_TAGS at override_settings level

comment:9 Changed 3 years ago by claudep

  • Patch needs improvement unset

Tests should pass now.

comment:10 Changed 3 years ago by julien

  • Triage Stage changed from Accepted to Ready for checkin

Great, thanks Claude!

comment:11 Changed 3 years ago by julien

  • Resolution set to fixed
  • Status changed from new to closed

In [17027]:

Fixed #16574 -- Strengthened the contrib.messages tests' isolation to avoid failures under certain project setting environments. Thanks to Boldewyn for the report and to Claude Paroz for the patch.

comment:12 Changed 3 years ago by julien

In [17032]:

Made some contrib.messages tests use override_settings for clarity. Thanks to Claude Paroz for the patch. Refs #16507, #16574.

Note: See TracTickets for help on using tickets.
Back to Top