diff --git a/.gitignore b/.gitignore index 32c2fec..e31007e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ /.mypy_cache /.pytest_cache /venv* +.vscode coverage-html dist diff --git a/pre_commit_hooks/tests_should_end_in_test.py b/pre_commit_hooks/tests_should_end_in_test.py index 7a1e7c0..9e89e39 100644 --- a/pre_commit_hooks/tests_should_end_in_test.py +++ b/pre_commit_hooks/tests_should_end_in_test.py @@ -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' ): diff --git a/tests/tests_should_end_in_test_test.py b/tests/tests_should_end_in_test_test.py index 4eb98e7..8d2adce 100644 --- a/tests/tests_should_end_in_test_test.py +++ b/tests/tests_should_end_in_test_test.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