A module to test code with pylint.
Editions Supported
- Community Edition
- Enterprise Edition
Test Pylint
test_pylint is Viindoo's continuous-integration quality gate. When its test
suite runs it lints a single target repository against Viindoo's coding
standards - Python (pylint + pylint_odoo, flake8), translations
(.po) and module packaging (manifest, images, documentation) - and fails
the build on any violation.
The module ships no user interface: it is driven entirely by running its tests.
What it checks
Each check is one test file under test_pylint/tests/:
- test_pylint - runs pylint (with the pylint_odoo plugin) over the
Python of every installable module in the target repository, restricted to
the curated ENABLED_CODES allow-list.
- test_flake8 - runs flake8 over the same Python.
- test_pofile - checks that every .po file (in i18n/ and
i18n_extra/) keeps the same number of %s placeholders between the
msgid and its msgstr.
- test_eslint - runs eslint over the modules' JavaScript.
- test_manifest_description - the manifest description renders as valid
reStructuredText.
- test_doc_index_rst - each module's doc/*.rst renders as valid
reStructuredText.
- test_manifest_images - every path in the manifest images key exists.
- test_same_module_name - no module technical name is defined twice across
the addons path.
Choosing which repository to check
Only ONE repository is linted per run, so a build never fails on pre-existing
issues in dependency repositories. The repository is resolved from the first
available of three sources, in this order:
- The .odoorc option repo_to_check_quality (this is what CI writes).
- The environment variable REPO_TO_CHECK_QUALITY.
- The current working directory - if you cd into the repository before
running, it is detected automatically from the addons path.
If none of the three resolves, the test_pylint / test_flake8 /
test_pofile checks skip rather than guess.
Running it locally
Install the tooling once:
pip install pylint pylint-odoo flake8
npm install -g eslint # only needed for test_eslint
The simplest way is to cd into the repository so it is auto-detected
(source 3 above):
cd /path/to/my_repo
odoo-bin -d <db> --addons-path=<core-addons>,/path/to/my_repo \
-i test_pylint --test-enable --test-tags=/test_pylint --stop-after-init
Or name the repository explicitly, without editing any config file
(source 2 above):
REPO_TO_CHECK_QUALITY=my_repo odoo-bin -d <db> --addons-path=... \
-u test_pylint --test-enable --test-tags=/test_pylint --stop-after-init
Use --test-tags=/test_pylint with the leading / to select the whole
module; a bare test_pylint would be read as a tag and match no test.
Linting only some modules
By default every installable module in the resolved repository is linted. To
lint only a subset - for example the modules a pull request actually changed -
set the .odoorc option modules_to_check_quality to a comma-separated
list of module technical names:
modules_to_check_quality = sale_extra, my_module
test_pylint, test_flake8 and test_pofile then lint only the
intersection of that list with the installable modules of the resolved
repository. When the option is absent, empty, or whitespace-only, the whole
repository is linted - byte-identical to the default behaviour.
On CI this option is written automatically for pull-request builds, computed
from the modules the PR changed, so a PR that touches one module no longer pays
to lint the whole repository. A build that changes only modules with nothing to
lint (for example an installable : False module, or a module that ships
no .po file) simply passes with nothing checked - it is not an error.
Notes
- pylint_odoo is required for test_pylint; if it is not installed the
check skips with an install hint (pip install pylint-odoo).
- flake8-bugbear is not part of the CI gate: the B / B9 codes in the
flake8 selection are inert there. If you have bugbear installed locally you
may see extra B950 line-length findings that do not fail CI.
This software and associated files (the "Software") may only be
used
(executed, modified, executed after modifications) if you have
purchased a
valid license from the authors, typically via Odoo Apps,
or if you
have
received a written agreement from the authors of the
Software (see the
COPYRIGHT file).
You may develop Odoo modules that use the Software as a library
(typically
by depending on it, importing it and using its
resources), but
without
copying any source code or material from the
Software. You may distribute
those modules under the license of your
choice, provided that this
license
is compatible with the terms of
the Odoo Proprietary License (For
example:
LGPL, MIT, or proprietary
licenses similar to this one).
It is forbidden to publish, distribute, sublicense, or sell
copies of the
Software or modified copies of the Software.
The above copyright notice and this permission notice must be
included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT
SHALL THE
AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING
FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE
SOFTWARE.