CSE developers follow Google's Python Style Guide. Note the use of strong typing throughout. Older versions of python allow you to get away without this but type checking avoids common errors that are tricky to debug.
CSE projects should check Python code with automated tools. pylint
is the minimum, but we prefer to run three different tools:
Black is a code formatting tool. It removes all need from pycodestyle
nagging about formatting so the team can focus on content vs style.
Pyflakes is a fast static analysis tool that identifies common errors in Python code.
PEP 8 is the accepted style guide.
PEP 257 are the encouraged Docstring conventions.
Flake8 is an option for teams who want a single wrapper for running Pyflakes and pycodestyle.
Unittest is a simple unit testing framework that provides the basics for unit testing: asserts, fixtures, mocks, etc. There is no need to install unittest
and tests can be run using:
python -m unittest
Pytest is a simple unit testing framework that provides the basics for unit testing: asserts, fixtures, etc...
pip3 install pytest
Mocking/stubbing framework that works with Pytest. Use this to mock out OS calls, off-box calls, and other calls that would unnecessarily broaden the scope of unit tests.
pip3 install pytest-mock