Merge branch 'issue638-ouput-file' into 'master'

options: Forward `--output-file` to be reparsed for BaseFormatter

Closes #637

See merge request pycqa/flake8!427
This commit is contained in:
Anthony Sottile 2020-05-12 05:21:11 +00:00
commit 00985a64bc
2 changed files with 20 additions and 1 deletions

View file

@ -112,7 +112,12 @@ class Application(object):
:rtype:
(argparse.Namespace, list)
"""
return self.prelim_arg_parser.parse_known_args(argv)
args, rest = self.prelim_arg_parser.parse_known_args(argv)
# XXX (ericvw): Special case "forwarding" the output file option so
# that it can be reparsed again for the BaseFormatter.filename.
if args.output_file:
rest.extend(("--output-file", args.output_file))
return args, rest
def exit(self):
# type: () -> None

View file

@ -246,3 +246,17 @@ def test_file_not_found(tmpdir, capsys):
out, err = capsys.readouterr()
assert out.startswith("i-do-not-exist:0:1: E902")
assert err == ""
def test_output_file(tmpdir, capsys):
"""Ensure that --output-file is honored."""
tmpdir.join('t.py').write('import os\n')
with tmpdir.as_cwd():
_call_main(['t.py', '--output-file=f'], retv=1)
out, err = capsys.readouterr()
assert out == err == ""
expected = "t.py:1:1: F401 'os' imported but unused\n"
assert tmpdir.join('f').read() == expected