summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric N. Vander Weele <ericvw@gmail.com>2019-08-28 16:20:38 -0400
committerEric N. Vander Weele <ericvw@gmail.com>2019-08-29 16:06:02 -0400
commitcf4bc53c127d7e6c29f69fcd0a1920d0aa88c023 (patch)
tree442ed06e7fc4bf4e90449f73e74d878b93bf8542 /tests
parent7708e5b4abca1c9437caf59907a10753a6a5b1c9 (diff)
downloadflake8-cf4bc53c127d7e6c29f69fcd0a1920d0aa88c023.tar.gz
Hoist passing through sys.argv at the CLI layer
`flake8.main.cli.main()` is the primary entry point for the command-line implementation of flake8 (invoked via `__main__` or `console_scripts`). Therefore, it is reasonable for the entry point to be responsible for obtaining command line arguments from `sys.argv` there. Note that `sys.argv[1:]` is necessary in order to strip off the script name. Formerly, this was not needed in `Application.parse_preliminary_options_and_args()`, which was using `sys.argv[:]` because the result of the argument parsing was just for determining additional configuration to be loaded. Then, the *real* CLI argument parsing was forwarding the original `None` value to `argparse.ArgumentParser.parse_args()`, which internally was obtaining arguments as `sys.argv[1:]`. Additionally, the contract for various argument parsing methods to be guaranteed a `List[str]`.
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_main.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py
index 001f1ff..72e9621 100644
--- a/tests/integration/test_main.py
+++ b/tests/integration/test_main.py
@@ -126,3 +126,13 @@ def test_bug_report_successful(capsys):
out, err = capsys.readouterr()
assert json.loads(out)
assert err == ''
+
+
+def test_obtaining_args_from_sys_argv_when_not_explicity_provided(capsys):
+ """Test that arguments are obtained from 'sys.argv'."""
+ with mock.patch('sys.argv', ['flake8', '--help']):
+ _call_main(None)
+
+ out, err = capsys.readouterr()
+ assert out.startswith('usage: flake8 [options] file file ...\n')
+ assert err == ''