Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23543 closed Cleanup/optimization (fixed)

Documentation how to test custom management command missing

Reported by: wittwerch Owned by: Danilo Bargen
Component: Documentation Version: 1.7
Severity: Normal Keywords:
Cc: Lagovas, mail@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation about custom management command misses a few points how to properly test them.
=> https://docs.djangoproject.com/en/1.7/howto/custom-management-commands/

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!

Change History (11)

comment:1 by Claude Paroz, 10 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Lagovas, 10 years ago

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.

comment:3 by Lagovas, 10 years ago

Cc: Lagovas added

comment:4 by Claude Paroz, 10 years ago

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).

comment:5 by Danilo Bargen, 10 years ago

Owner: changed from nobody to Danilo Bargen
Status: newassigned

comment:6 by Danilo Bargen, 10 years ago

Cc: mail@… added
Has patch: set

comment:7 by Tim Graham, 10 years ago

Patch needs improvement: set

Comments for improvement are on the PR.

comment:8 by Tim Graham, 10 years ago

Patch needs improvement: unset

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

Resolution: fixed
Status: assignedclosed

In cdee8659763ee7044c1507bcd2202581b1744f0b:

Fixed #23543 -- Added docs on testing management command output.

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

In 60cf46fdf5176eb24ba4d47441ed24104f1493cc:

[1.7.x] Fixed #23543 -- Added docs on testing management command output.

Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master

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

In 276332d85c76a4de9fc1cb4bcb2f1636c0322414:

[1.6.x] Fixed #23543 -- Added docs on testing management command output.

Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master

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