mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
add exclude pattern to test names hook
This commit is contained in:
parent
634383cffd
commit
a977384397
3 changed files with 22 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -7,5 +7,6 @@
|
|||
/.mypy_cache
|
||||
/.pytest_cache
|
||||
/venv*
|
||||
.vscode
|
||||
coverage-html
|
||||
dist
|
||||
|
|
|
|||
|
|
@ -15,6 +15,11 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
|||
'--django', default=False, action='store_true',
|
||||
help='Use Django-style test naming pattern (test*.py)',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--exclude', default='facto.*.py',
|
||||
help='Use to exclude a certain pattern from check default to factory (fact*.py)',
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
retcode = 0
|
||||
|
|
@ -23,6 +28,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
|||
base = os.path.basename(filename)
|
||||
if (
|
||||
not re.match(test_name_pattern, base) and
|
||||
not re.match(args.exclude, base) and
|
||||
not base == '__init__.py' and
|
||||
not base == 'conftest.py'
|
||||
):
|
||||
|
|
|
|||
|
|
@ -34,3 +34,18 @@ def test_main_not_django_fails():
|
|||
def test_main_django_fails():
|
||||
ret = main(['--django', 'foo_test.py', 'test_bar.py', 'test_baz.py'])
|
||||
assert ret == 1
|
||||
|
||||
|
||||
def test_exclude_default_factory_files():
|
||||
ret = main(['--django', 'test_bar.py', 'test_baz.py', 'factory.py', 'factories.py'])
|
||||
assert ret == 0
|
||||
|
||||
|
||||
def test_exclude_custom_files_files():
|
||||
ret = main(['--django', '--exclude=tty.*.py', 'test_bar.py', 'test_baz.py', 'tty124.py', 'tty_file.py'])
|
||||
assert ret == 0
|
||||
|
||||
|
||||
def test_exclude_no_match_files():
|
||||
ret = main(['--django', 'test_bar.py', 'test_baz.py', 'tty_file.py'])
|
||||
assert ret == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue