diff --git a/pytest_codestyle.py b/pytest_codestyle.py index 7672b57..8bfe158 100644 --- a/pytest_codestyle.py +++ b/pytest_codestyle.py @@ -20,14 +20,15 @@ def pytest_addoption(parser): ignored=pycodestyle.DEFAULT_IGNORE.replace(',', ' '))) parser.addini('codestyle_show_source', type="bool", default=True, help='show source code for each error (default: True)') - parser.addini('codestyle_exclude', type="pathlist", + parser.addini('codestyle_exclude', type="args", help='source files to be excluded from codestyle') def pytest_collect_file(parent, path): config = parent.config - if config.getoption('codestyle') and path.ext == '.py' and path not in config.getini('codestyle_exclude'): - return Item(path, parent) + if config.getoption('codestyle') and path.ext == '.py': + if not any(path.fnmatch(pattern) for pattern in config.getini('codestyle_exclude')): + return Item(path, parent) class Item(pytest.Item, pytest.File): diff --git a/test_pytest_codestyle.py b/test_pytest_codestyle.py index 1426c87..a3c0576 100644 --- a/test_pytest_codestyle.py +++ b/test_pytest_codestyle.py @@ -46,9 +46,9 @@ def test_ini(request): ignore = ['d', 'e', 'f'] assert config.getini('codestyle_ignore') == ignore assert config.getini('codestyle_show_source') is True - exclude = ['{dirname}/{base}/exclude.py', '{dirname}/{base}/path/to/another/exclude.py'] + exclude = ['exclude.py', 'path/to/another/exclude.py'] assert config.getini('codestyle_exclude') == exclude - """.format(dirname=testdir.tmpdir.dirname, base=testdir.tmpdir.basename)) + """) p = p.write(p.read() + "\n") result = testdir.runpytest('--codestyle') result.assert_outcomes(passed=2) @@ -65,13 +65,14 @@ def test_pytest_collect_file(testdir): def test_pytest_collect_file_with_exclude(testdir): testdir.makeini(""" [pytest] - codestyle_exclude = a.py path/to/c.py + codestyle_exclude = a.py path/**/?.py """) testdir.tmpdir.ensure('a.py') testdir.tmpdir.ensure('b.py') testdir.tmpdir.ensure('path/to/c.py') + testdir.tmpdir.ensure('path/to/hoge/foo.py') result = testdir.runpytest('--codestyle') - result.assert_outcomes(passed=1) + result.assert_outcomes(passed=2) def test_cache(testdir):