summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-04-13 21:54:12 -0400
committerNed Batchelder <ned@nedbatchelder.com>2017-04-13 21:54:12 -0400
commit199bc04b9ed2038ca0e714d3b2d5c705030f1cb6 (patch)
tree82b188fbdda7341c1e198522f48600a66537b550
parent2db1f5be5a0e57128e7192e415e986815df2b018 (diff)
downloadpython-coveragepy-199bc04b9ed2038ca0e714d3b2d5c705030f1cb6.tar.gz
Print command-line errors to stderr instead of stdout
-rw-r--r--CHANGES.rst3
-rw-r--r--coverage/cmdline.py6
-rw-r--r--tests/test_cmdline.py20
3 files changed, 16 insertions, 13 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index e20d9bd..d3495ec 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -10,7 +10,8 @@ Change history for Coverage.py
Unreleased
----------
-- Nothing yet.
+- Errors printed by the ``coverage`` command now go to stderr instead of
+ stdout.
Version 4.4b1 --- 2017-04-04
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index a9af9f3..9c908b1 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -3,6 +3,8 @@
"""Command-line support for coverage.py."""
+from __future__ import print_function
+
import glob
import optparse
import os.path
@@ -533,8 +535,8 @@ class CoverageScript(object):
"""Display an error message, or the named topic."""
assert error or topic or parser
if error:
- print(error)
- print("Use '%s help' for help." % (self.program_name,))
+ print(error, file=sys.stderr)
+ print("Use '%s help' for help." % (self.program_name,), file=sys.stderr)
elif parser:
print(parser.format_help().strip())
else:
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 000bf46..30fb06e 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -462,16 +462,16 @@ class CmdLineTest(BaseCmdLineTest):
def test_bad_concurrency(self):
self.command_line("run --concurrency=nothing", ret=ERR)
- out = self.stdout()
- self.assertIn("option --concurrency: invalid choice: 'nothing'", out)
+ err = self.stderr()
+ self.assertIn("option --concurrency: invalid choice: 'nothing'", err)
def test_no_multiple_concurrency(self):
# You can't use multiple concurrency values on the command line.
# I would like to have a better message about not allowing multiple
# values for this option, but optparse is not that flexible.
self.command_line("run --concurrency=multiprocessing,gevent foo.py", ret=ERR)
- out = self.stdout()
- self.assertIn("option --concurrency: invalid choice: 'multiprocessing,gevent'", out)
+ err = self.stderr()
+ self.assertIn("option --concurrency: invalid choice: 'multiprocessing,gevent'", err)
def test_multiprocessing_needs_config_file(self):
# You can't use command-line args to add options to multiprocessing
@@ -480,7 +480,7 @@ class CmdLineTest(BaseCmdLineTest):
self.command_line("run --concurrency=multiprocessing --branch foo.py", ret=ERR)
self.assertIn(
"Options affecting multiprocessing must be specified in a configuration file.",
- self.stdout()
+ self.stderr()
)
def test_run_debug(self):
@@ -530,11 +530,11 @@ class CmdLineTest(BaseCmdLineTest):
def test_run_nothing(self):
self.command_line("run", ret=ERR)
- self.assertIn("Nothing to do", self.stdout())
+ self.assertIn("Nothing to do", self.stderr())
def test_cant_append_parallel(self):
self.command_line("run --append --parallel-mode foo.py", ret=ERR)
- self.assertIn("Can't append to data files in parallel mode.", self.stdout())
+ self.assertIn("Can't append to data files in parallel mode.", self.stderr())
def test_xml(self):
# coverage xml [-i] [--omit DIR,...] [FILE1 FILE2 ...]
@@ -662,9 +662,9 @@ class CmdLineStdoutTest(BaseCmdLineTest):
def test_error(self):
self.command_line("fooey kablooey", ret=ERR)
- out = self.stdout()
- self.assertIn("fooey", out)
- self.assertIn("help", out)
+ err = self.stderr()
+ self.assertIn("fooey", err)
+ self.assertIn("help", err)
class CmdMainTest(CoverageTest):