pytest
Terminal > New Terminal
menu)pip3 install pytest
Note: If you get an error, you might have to run pip3 install --user pytest
Then, put import pytest
at the top of your Python test file.
All of your tests must be contained within functions that begin with test_
Example of good testing:
s.lower()
instead.Write docstrings for all functions, including helper and nested functions.
A good docstring gives a description of the function, including its input(s) and output. Ideally, by looking at the docstring you know what the function does and how to use it without looking at the function body itself.
You can include docstrings as a comment with """
just below your function signatures. E.g.
Give constants and helper functions useful names.
All functions require type annotations on inputs and output. You can omit output annotation for functions that have no return (for example functions that only need to print
).
Names of constants and functions should be lower case and underscore separated. For configuration constants (for example the height of a character) it is acceptable to use all caps names.
Keep lines under 80 characters.
Indent your code properly. If you are using Pycharm, this should be happening automatically. If you are not using Pycharm, use 4 spaces to indent your code (not the tab character) and keep arguments of functions lined up:
return
statements should be not be written like this:but rather like this:
if
statements should be written with newlines: