summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2020-06-19 10:01:04 -0700
committerAnthony Sottile <asottile@umich.edu>2020-06-19 10:01:04 -0700
commitb40af6737ed5feb7d519dc2d0277d8664a802067 (patch)
treef9bc28e7386fba8ffb9de62c15ac1c25173c9c19
parenta7be77f761a4c29121d6bb6f61c11902281f9105 (diff)
downloadflake8-b40af6737ed5feb7d519dc2d0277d8664a802067.tar.gz
Add option to disable show-source for calling tools
-rw-r--r--src/flake8/main/options.py7
-rw-r--r--tests/integration/test_main.py25
2 files changed, 32 insertions, 0 deletions
diff --git a/src/flake8/main/options.py b/src/flake8/main/options.py
index 4504634..a0f066f 100644
--- a/src/flake8/main/options.py
+++ b/src/flake8/main/options.py
@@ -282,6 +282,13 @@ def register_default_options(option_manager):
parse_from_config=True,
help="Show the source generate each error or warning.",
)
+ add_option(
+ "--no-show-source",
+ action="store_false",
+ dest="show_source",
+ parse_from_config=False,
+ help="Negate --show-source",
+ )
add_option(
"--statistics",
diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py
index ce8ad13..a2b7aa1 100644
--- a/tests/integration/test_main.py
+++ b/tests/integration/test_main.py
@@ -108,6 +108,31 @@ t.py:2:1: F401 'sys' imported but unused
assert err == ''
+def test_show_source_option(tmpdir, capsys):
+ """Ensure that --show-source and --no-show-source work."""
+ with tmpdir.as_cwd():
+ tmpdir.join('tox.ini').write('[flake8]\nshow_source = true\n')
+ tmpdir.join('t.py').write('import os\n')
+ _call_main(['t.py'], retv=1)
+
+ out, err = capsys.readouterr()
+ assert out == '''\
+t.py:1:1: F401 'os' imported but unused
+import os
+^
+'''
+ assert err == ''
+
+ with tmpdir.as_cwd():
+ _call_main(['t.py', '--no-show-source'], retv=1)
+
+ out, err = capsys.readouterr()
+ assert out == '''\
+t.py:1:1: F401 'os' imported but unused
+'''
+ assert err == ''
+
+
def test_extend_exclude(tmpdir, capsys):
"""Ensure that `flake8 --extend-exclude` works."""
for d in ['project', 'vendor', 'legacy', '.git', '.tox', '.hg']: