Backport of 5853c87a458f62ebd62d7809168355610de2570c from master.
Conflicts:
django/core/management/commands/sqlmigrate.py
tests/user_commands/tests.py
This option is not actually very useful in the general case
because it doesn't override sys.stdin.
It's still marginally useful for testing some features of
the createsuperuser command so it was moved there.
This commit also makes the detection of a TTY in createsuperuser
a bit more robust, after a suggestion of appolo13.