Module để kiểm thử mã nguồn với pylint.
Ấn bản được Hỗ trợ
- Ấn bản Community
- Ấn bản Enterprise
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.
Phần mềm này và các tệp liên kết ("Phần mềm")
được sử dụng (chạy, tuỳ biến, chạy sau khi được tuỳ biến)
chỉ khi bạn mua được giấy phép có hiệu lực từ tác giả,
điển hình như qua các Ứng dụng Odoo, hoặc trong trường hợp
bạn nhận được thoả thuận bằng văn bản từ tác giả của Phần mềm (chi tiết tại tệp COPYRIGHT).
Bạn có thể phát triển các phân hệ Odoo có sử dụng Phần mềm như một Thư viện (thường là phụ thuộc vào, nhập vào và sử dụng nguồn của nó)
nhưng không sao chéo bất kỳ mã nguồn hay tài liệu nào thuộc Phần mềm. Bạn có thể phân phối những phân hệ này theo giấy phép
mà bạn lựa chọn, miễn sao nội dung giấy phép đó tương tích với điều khoản của Giấy phép Phần mềm Độc quyền Odoo
(ví dụ: LGPL, MIT hay bất kỳ loại giấy phép phần mềm độc quyền nào tương tự vậy).
Nghiêm cấm phát hành, phân phối, cấp phép lại hoặc bán bản sao của Phần mềm hoặc
bản sao
Phần mềm đã được sửa đổi.
Thông báo bản quyền và chấp thuận nêu trên buộc phải được bao gồm trong tất cả các bản sao hoặc các phần quan trọng của Phần mềm.
PHẦN MỀM ĐƯỢC CUNG CẤP "NGUYÊN TRẠNG", KHÔNG BẢO ĐẢM DƯỚI BẤT KỲ HÌNH THỨC NÀO, ĐƯỢC THỂ HIỆN RÕ RÀNG HOẶC NGỤ Ý, KHÔNG GIỚI HẠN
ĐẢM BẢO VỀ CÁC BẢO ĐẢM NGỤ Ý VỀ KHẢ NĂNG THƯƠNG MẠI, PHÙ HỢP VỚI MỤC ĐÍCH CỤ THỂ VÀ KHÔNG VI PHẠM.
TRONG MỌI TRƯỜNG HỢP SẼ KHÔNG CÓ TÁC GIẢ HOẶC CHỦ SỞ HỮU BẢN QUYỀN NÀO CHỊU TRÁCH NHIỆM VỀ BẤT KỲ KHIẾU NẠI,
THIỆT HẠI HOẶC TRÁCH NHIỆM PHÁP LÝ KHÁC NÀO TRONG PHẠM VI HỢP ĐỒNG, CÁC THIỆT HẠI HOẶC CÁCH KHÁC, PHÁT SINH TỪ, NGOÀI HOẶC
CÓ LIÊN KẾT VỚI PHẦN MỀM HOẶC VIỆC SỬ DỤNG HOẶC KINH DOANH KHÁC TẠI PHẦN MỀM.