Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add command line option to show current configuration #1114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions coverage/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ class Opts(object):
'--show-contexts', action='store_true',
help="Show contexts for covered lines.",
)
show_omit = optparse.make_option(
'--show-omit', action='store_true',
help="Show omit entries in coverage config files.",
)
omit = optparse.make_option(
'', '--omit', action='store',
metavar="PAT1,PAT2,...",
Expand Down Expand Up @@ -212,6 +216,7 @@ def __init__(self, *args, **kwargs):
append=None,
branch=None,
concurrency=None,
config=None,
context=None,
debug=None,
directory=None,
Expand All @@ -231,6 +236,7 @@ def __init__(self, *args, **kwargs):
skip_covered=None,
skip_empty=None,
show_contexts=None,
show_omit=None,
sort=None,
source=None,
timid=None,
Expand Down Expand Up @@ -351,6 +357,20 @@ def get_prog_name(self):
),
),

'config': CmdOptionParser(
"config",
[
Opts.show_omit,
Opts.output_json,
] + GLOBAL_ARGS,
usage="[options] [modules]",
description=(
"Get current configuration. "
"Topics are: "
"'omit' to show configuration omit entries in list format; "
),
),

'debug': CmdOptionParser(
"debug", GLOBAL_ARGS,
usage="<topic>",
Expand Down Expand Up @@ -610,6 +630,18 @@ def command_line(self, argv):

self.coverage.load()

if options.action == "config":
# Allows end user to see omit settings
# Useful since there are several configuration files in many different formats
# Which do environment variable expansion, etc
if options.show_omit:
if options.outfile == "json":
print(self.coverage.config.run_omit)
else:
joined_string = ",".join(self.coverage.config.run_omit)
print(joined_string)
return OK

total = None
if options.action == "report":
total = self.coverage.report(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class BaseCmdLineTest(CoverageTest):
directory=None, ignore_errors=None, include=None, omit=None, morfs=[],
contexts=None,
)
_defaults.Coverage().config(
show_omit=None, json=None
)
_defaults.Coverage().html_report(
directory=None, ignore_errors=None, include=None, omit=None, morfs=[],
skip_covered=None, show_contexts=None, title=None, contexts=None,
Expand Down Expand Up @@ -252,6 +255,11 @@ def test_debug(self):
self.cmd_help("debug", "What information would you like: config, data, sys, premain?")
self.cmd_help("debug foo", "Don't know what you mean by 'foo'")

def test_config(self):
self.command_line("config")
out = self.stdout()
assert "" in out

def test_debug_sys(self):
self.command_line("debug sys")
out = self.stdout()
Expand Down