An extension for Flake8 to make sure that test function name follows a given convention
When both Flake8 and flake8-test-name
are installed, the plugin
will show up when displaying the version of flake8
:
$ flake8 --version
3.6.0 (flake8-test-name: 0.1.2, […]
The hook assumes that your:
- test files are matching
test_.*.py
- test functions are starting with
test_
Any function matching these 2 conditions will be validated against your custom validator
This module can be configured in 2 ways.
First option is a regex using --test-func-name-validator-regex
:
$ flake8 myproject/tests/sample.py --test-func-name-validator-regex="test_funky_convention_.*" --select=TN101
>> myproject/tests/sample.py:14:1: TN101 test function name does not match the convention (test_invalid_method_sample)
Second option is with a python module containing a method named test_function_name_validator
.
Assuming you have a funky_validator.py file with the following content:
def test_function_name_validator(func_name: str):
return func_name.startswith("test_funkyconvention")
You can then configure it using --test-func-name-validator-module
:
$ flake8 myproject/tests/sample.py --test-func-name-validator-module=./funky_validator.py --select=TN101
>> myproject/tests/sample.py:14:1: TN101 test function name does not match the convention (test_invalid_method_sample)
This plugin is using the following error codes:
Code | Error | |
TN101 | TN101 test function name does not match the convention |
- fix in options parser for flake8 > 6.0
- minor refactoring and doc improvement
- Initial release