#23663: Commands classes are not properly testable due to their initialization 
in
execute() method!
-------------------------------------+-------------------------------------
     Reporter:  daveoncode           |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  1.7
    Component:  Core (Management     |               Resolution:
  commands)                          |             Triage Stage:
     Severity:  Normal               |  Unreviewed
     Keywords:  test, tdd,           |      Needs documentation:  0
  management, commands               |  Patch needs improvement:  0
    Has patch:  0                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  1                    |
-------------------------------------+-------------------------------------
Changes (by berkerpeksag):

 * cc: berker.peksag@… (added)


Comment:

 Alternatively, you can use `io.StringIO` instead of `OutputMock`.

 {{{#!python
 import io

 class SpamTest(TestCase):

     def setUp(self):
         self.command = Command()
         self.command.stdout = io.StringIO()
         self.command.stderr = io.StringIO()
 }}}


 This way, you can also test the output easily (e.g. something like
 `self.assertFalse(self.command.stderr.getvalue())`).

--
Ticket URL: <https://code.djangoproject.com/ticket/23663#comment:2>
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/068.ce20821be7f122a3d4adf1b5777eec93%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to