#24721: Introduce something similar to mail.outbox for messages
----------------------------------+--------------------------------------
     Reporter:  mjtamlyn          |                    Owner:  nobody
         Type:  New feature       |                   Status:  new
    Component:  contrib.messages  |                  Version:  master
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------

Comment (by mjtamlyn):

 A more explicit design possibility which doesn't require so much end user
 code and provides a more explicit (and more optional) hook:

 {{{
 # settings.py
 TEST_RUNNER = 'myproject.test_runner.TestRunner'

 # test_runner.py
 class TestRunner(DiscoverRunner):
     test_extensions = [messages.test.MessagesExtension,
 django_redis.test.TestExtension]
 }}}

 Each extension class would have hooks for test environment setup and
 teardown, before/after each test case and individual test.

 At the moment I find most third party apps are very bad at making it easy
 to use them in a suitable manner for tests - I hope by introducing an
 official API and making it easy for users they will consider more
 providing utilities for testing.

 I'd love to find an elegant way for these extensions to provide custom
 assertion methods as well, for example {{{self.assertMessageSent('you
 failed', level=messages.ERROR)}}}, but this would require something more
 magical involving getattrs, deliberate monkeypatching on of methods or
 something equally ugly.

 At this point it does start looking a lot like stuff pytest has done
 better. Personally I've not had the chance to use it a huge amount yet,
 but it does look good. I think that pytest is now big enough and
 established enough that we could consider adding a
 {{{django.test.pytest}}} module with utilities along the lines of those in
 {{{pytest-django}}}.

 Mind you, if we are talking about magical code in test utilities, pytest
 takes it to a whole new level ;)

--
Ticket URL: <https://code.djangoproject.com/ticket/24721#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.9311554a01121c08e23e53d9fd166b82%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to