summaryrefslogtreecommitdiff
path: root/coverage/cmdline.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/cmdline.py')
-rw-r--r--coverage/cmdline.py51
1 files changed, 30 insertions, 21 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 7b86054e..edbc1d25 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -1,5 +1,5 @@
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
"""Command-line support for coverage.py."""
@@ -14,6 +14,7 @@ import traceback
from coverage import env
from coverage.collector import CTracer
+from coverage.data import line_counts
from coverage.debug import info_formatter, info_header
from coverage.execfile import run_python_file, run_python_module
from coverage.misc import BaseCoverageException, ExceptionDuringRun, NoSource
@@ -42,9 +43,13 @@ class Opts(object):
"Valid values are: %s."
) % ", ".join(CONCURRENCY_CHOICES),
)
+ context = optparse.make_option(
+ '', '--context', action='store', metavar="LABEL",
+ help="The context label to record for this coverage run",
+ )
debug = optparse.make_option(
'', '--debug', action='store', metavar="OPTS",
- help="Debug options, separated by commas",
+ help="Debug options, separated by commas. [env: COVERAGE_DEBUG]",
)
directory = optparse.make_option(
'-d', '--directory', action='store', metavar="DIR",
@@ -115,7 +120,11 @@ class Opts(object):
)
rcfile = optparse.make_option(
'', '--rcfile', action='store',
- help="Specify configuration file. Defaults to '.coveragerc'",
+ help=(
+ "Specify configuration file. "
+ "By default '.coveragerc', 'setup.cfg' and 'tox.ini' are tried. "
+ "[env: COVERAGE_RCFILE]"
+ ),
)
source = optparse.make_option(
'', '--source', action='store', metavar="SRC1,SRC2,...",
@@ -124,7 +133,7 @@ class Opts(object):
timid = optparse.make_option(
'', '--timid', action='store_true',
help=(
- "Use a simpler but slower trace method. Try this if you get "
+ "Use a simpler but slower trace method. Try this if you get "
"seemingly impossible results!"
),
)
@@ -155,6 +164,7 @@ class CoverageOptionParser(optparse.OptionParser, object):
append=None,
branch=None,
concurrency=None,
+ context=None,
debug=None,
directory=None,
fail_under=None,
@@ -353,6 +363,7 @@ CMDS = {
Opts.append,
Opts.branch,
Opts.concurrency,
+ Opts.context,
Opts.include,
Opts.module,
Opts.omit,
@@ -386,8 +397,10 @@ OK, ERR, FAIL_UNDER = 0, 1, 2
class CoverageScript(object):
"""The command-line interface to coverage.py."""
- def __init__(self, _covpkg=None, _run_python_file=None,
- _run_python_module=None, _help_fn=None, _path_exists=None):
+ def __init__(
+ self, _covpkg=None, _run_python_file=None,
+ _run_python_module=None, _help_fn=None,
+ ):
# _covpkg is for dependency injection, so we can test this code.
if _covpkg:
self.covpkg = _covpkg
@@ -399,7 +412,6 @@ class CoverageScript(object):
self.run_python_file = _run_python_file or run_python_file
self.run_python_module = _run_python_module or run_python_module
self.help_fn = _help_fn or self.help
- self.path_exists = _path_exists or os.path.exists
self.global_option = False
self.coverage = None
@@ -475,6 +487,8 @@ class CoverageScript(object):
include=include,
debug=debug,
concurrency=options.concurrency,
+ check_preimported=True,
+ context=options.context,
)
if options.action == "debug":
@@ -607,14 +621,14 @@ class CoverageScript(object):
# they will be None if they have not been specified.
if getattr(options, opt_name) is not None:
self.help_fn(
- "Options affecting multiprocessing must be specified "
- "in a configuration file."
+ "Options affecting multiprocessing must only be specified "
+ "in a configuration file.\n"
+ "Remove --{} from the command line.".format(opt_name)
)
return ERR
- if not self.coverage.get_option("run:parallel"):
- if not options.append:
- self.coverage.erase()
+ if options.append:
+ self.coverage.load()
# Run the script.
self.coverage.start()
@@ -623,18 +637,13 @@ class CoverageScript(object):
if options.module:
self.run_python_module(args[0], args)
else:
- filename = args[0]
- self.run_python_file(filename, args)
+ self.run_python_file(args[0], args)
except NoSource:
code_ran = False
raise
finally:
self.coverage.stop()
if code_ran:
- if options.append:
- data_file = self.coverage.get_option("run:data_file")
- if self.path_exists(data_file):
- self.coverage.combine(data_paths=[data_file])
self.coverage.save()
return OK
@@ -654,12 +663,12 @@ class CoverageScript(object):
print(" %s" % line)
elif info == 'data':
self.coverage.load()
- data = self.coverage.data
+ data = self.coverage.get_data()
print(info_header("data"))
- print("path: %s" % self.coverage.data_files.filename)
+ print("path: %s" % self.coverage.get_data().filename)
if data:
print("has_arcs: %r" % data.has_arcs())
- summary = data.line_counts(fullpath=True)
+ summary = line_counts(data, fullpath=True)
filenames = sorted(summary.keys())
print("\n%d files:" % len(filenames))
for f in filenames: