When we have more and more team members joining the development team, we may want make sure the code quarlity does not drop down and make the code style consistent, in Python world there are tools exist to make sure this happen.

python-grpc

pytest-cov

pytest-cov is a pytest plugin to help us to calculate the code coverage and enforce code coverage to be at some level, to install the package use pipenv install pytest-cov --dev to make it as a development dependency, to config it add the following lines into tox.ini, it will work, we could modify --cov=xx to include the package we want to enforce the coverage, in grpc-mate we could simple ignore the auto generated code

[tool:pytest]

[pytest]
addopts = --cov=service/ --cov=data_store/ --cov-fail-under=90

after we run make pytest we could get result like below, if the coverage does not meet expectation, the build will fail

---------- coverage: platform darwin, python 3.6.8-final-0 -----------
Name                                 Stmts   Miss  Cover
--------------------------------------------------------
data_store/__init__.py                   6      0   100%
data_store/db.py                        11      3    73%
data_store/models.py                    10      0   100%
service/__init__.py                      0      0   100%
service/greeter_servicer.py              8      0   100%
service/product_read_servicer.py        36      2    94%
service/product_update_servicer.py      16      0   100%
--------------------------------------------------------
TOTAL                                   87      5    94%

Required test coverage of 90% reached. Total coverage: 94.25%

pycodestyle

PEP 8 is the standard python style guide line, and pycodestyle is the tool to make sure our code is align with PEP 8, to install the package use pipenv install pycodestyle --dev to make it as a development dependency, to config it , add the following lines into tox.ini, it will work, in the configuration we could also config which type of check we could ignore and override some default PEP 8 config

[pycodestyle]
ignore = E722
max-line-length = 120
statistics = True

if anything does not align with the PEP 8, the build will fail.

After we config these tools we could make sure all the developers share the same code style and make sure the code coverage never drop down, we also need CI tool's support to build the project automaticaly, fail the build when any config rule gets broken and send out alert to responsible developers to fix.