Add OptionManager#parse_known_args

If a user specified `--max-complexity` on the command-line, they
would be told that it did not exist. The same would be true of any
option provided by a plugin. This is because we parse the command-line
arguments twice in Flake8 -- the first time to specify the verbosity
and destination for logging, the second time to actually execute Flake8.
Since plugin options are not registered to start with the first time,
they are not valid options. So when we first parse the options, we should
only attempt to parse the ones which we know about.

Closes #168
This commit is contained in:
Ian Cordasco 2016-07-16 10:07:19 -05:00
parent 43df3ecf74
commit 73be9b0e90
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
3 changed files with 47 additions and 4 deletions

View file

@ -2,6 +2,7 @@
import optparse
import os
import mock
import pytest
from flake8 import utils
@ -194,3 +195,11 @@ def test_extend_default_ignore(optmanager):
assert optmanager.extended_default_ignore == set(['T100',
'T101',
'T102'])
def test_parse_known_args(optmanager):
"""Verify we ignore unknown options."""
with mock.patch('sys.exit') as sysexit:
optmanager.parse_known_args(['--max-complexity', '5'])
assert sysexit.called is False