Released on pypi. Install with
pip install py-gardener
Py-Gardener enforces best practices for your python project.
Check out SETUP.md
Please open a github issue.
Copy the example test file to the following folder with class TestGardener
:
$PROJECT_DIR/tests/static/test_gardener.py
Fields:
ROOT_DIR
: The root path of the project.
TEST_DIR
: The test path of the project.
LIB_DIR
: The source code of the project.
DOCKER
: Optional list of Docker containers the project is developed against.
EXCLUDE
: List of files to be not considered project files for test directory. Defaults to ["env"]
.
OPTIONS
: General options specified below:
max-line-length
: Default 80, max line length for pylint and PEP8 rules.
Test asserts don't check val in (True, False)
. This can result in false positives when val == 1 or val == 0
.
Use isinstance(val, bool)
instead
Incorrect:
>>> 0 in (True, False)
True
>>> 1 in (True, False)
True
Correct:
>>> isinstance(0, bool)
False
Test that lines do not end with backslash - use parenthesis instead
Incorrect:
assert 'key' in values or \
condition is True
Correct:
assert (
'key' in values or
condition is True
)
Test that we conform to PEP8.
Test that we conform to Pylint.
Pylint requires a config to adhere to.
To generate the default config, run:
$ pylint --generate-rcfile > .pylintrc
To add different configurations for sub-directories, include a separate .pylintrc
at the root of the subdirectory.
Example:
$PROJECT_ROOT
|-- Dir1
| |-- file1.py
|-- Dir2
| |-- Dir3
| | |-- file2.py
| |-- file3.py
| |-- .pylintrc
|-- .pylintrc
In the above scenario, file1.py
would be validated against $PROJECT_ROOT/.pylintrc
whereas file2.py
& file3.py
would be validated against $PROJECT_ROOT/Dir2/.pylintrc
.
Test that test class names are correct. (Test class name must match file name)
For example:
test_Example.py
import unittest
class TestExample(unittest.TestCase):
...
Check test files have corresponding $LIB_DIR
file if folder exists.
Example:
$TEST_DIR/dir/test_Example.py
requires $LIB_DIR/dir/Example.py
if $LIB_DIR/dir
exists.
Check that all sub folders in $TEST_DIR have an __init__.py
file.
Only validates if $PROJECT_ROOT/setup.py
exists
Test setup.py version doesn't fall behind git tag.
Only validates if DOCKER
(above) is not an empty list
Test that tests are run inside a Docker container.