Check your code style
PEP 8 is the Python code style guide, and it sets out rules for things like line length, indentation, multi-line expressions, and naming conventions
1. Pylint
Pylint is a library that checks for PEP 8 style violations and common errors.
can also be run from the command line.
To install, run pip install pylint.
To use Pylint from the command line, run pylint
path/to/dir or pylint [options] path/to/module.py. Pylint will output warnings about style violations and other errors to the console.
You can customize what errors Pylint checks for with a configuration file called pylintrc.
Outsource your code style
Remembering to run linters manually from the command line for each file you change is a pain,
A great solution is to use a library that automatically reformats your code into something that passes PEP 8 for you.
1.Autopep8
Autopep8 automatically formats the code in the module you specify. It will re-indent lines, fix indentation, remove extraneous whitespace, and refactor common comparison mistakes (like with booleans and None).
To install, run pip install --upgrade autopep8.
To reformat code in place, run autopep8 --in-place --aggressive --aggressive <filename>. The aggressive flags (and the number of them) indicate how much control you want to give autopep8 over your code style
Check your test coverage
You’re writing tests, right? Then you will want to make sure new code committed to your codebase is tested and doesn’t drop your overall amount of test coverage.
For measuring test coverage, we have one recommendation: Coverage.
Coverage has several options for the way it reports your test coverage to you, including outputting results to the console or to an HTML page and indicating which line numbers are missing test coverage
To install, run pip install coverage. To run a program and see its output,
run coverage run [path/to/module.py] [args], and you will see your program’s output.
To see a report of which lines of code are missing coverage, run coverage report -m.