For example the documentation states that you should use self.stdout: "By
using these proxies, it becomes much easier to test your custom command"
But how to actually test the output is missing. A complete example with
call_command would be great!
--
Ticket URL: <https://code.djangoproject.com/ticket/23543>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:1>
Comment (by Lagovas):
You can test commands like any other function. Just
{{{
from django.core.management import call_command
class SomeTest(TestCase):
def test_command(self):
call_command('your_command', *args, **kwargs)
self.assertTrue(somethingDone())
}}}
and test result or behavior of your command. I think no sense for writing
how to test all functions or methods from docs.
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:2>
* cc: Lagovas (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:3>
Comment (by claudep):
I think an example wouldn't hurt, and show how you can catch the command
output with `six.StringIO` (see `tests/user_commands/tests.py`).
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:4>
* status: new => assigned
* owner: nobody => dbrgn
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:5>
* cc: mail@… (added)
* has_patch: 0 => 1
Comment:
Pull request: https://github.com/django/django/pull/3517
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:6>
* needs_better_patch: 0 => 1
Comment:
Comments for improvement are on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:7>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"cdee8659763ee7044c1507bcd2202581b1744f0b"]:
{{{
#!CommitTicketReference repository=""
revision="cdee8659763ee7044c1507bcd2202581b1744f0b"
Fixed #23543 -- Added docs on testing management command output.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"60cf46fdf5176eb24ba4d47441ed24104f1493cc"]:
{{{
#!CommitTicketReference repository=""
revision="60cf46fdf5176eb24ba4d47441ed24104f1493cc"
[1.7.x] Fixed #23543 -- Added docs on testing management command output.
Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"276332d85c76a4de9fc1cb4bcb2f1636c0322414"]:
{{{
#!CommitTicketReference repository=""
revision="276332d85c76a4de9fc1cb4bcb2f1636c0322414"
[1.6.x] Fixed #23543 -- Added docs on testing management command output.
Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23543#comment:11>