Skip to content

Commit 4d42993

Browse files
authored
Merge pull request #77 from ForgeFlow/add-checklog-odoo
[ADD] oca_checklog_odoo: configurable failure on WARNING log messages
2 parents af663c6 + 8dbb91e commit 4d42993

10 files changed

Lines changed: 60 additions & 4 deletions

File tree

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ RUN apt-get update -qq \
9090

9191
# We use manifestoo to check licenses, development status and list addons and dependencies
9292
RUN pipx install --pip-args="--no-cache-dir" "manifestoo>=0.3.1"
93+
# Used in oca_checklog_odoo to check odoo logs for errors and warnings
94+
RUN pipx install --pip-args="--no-cache-dir" checklog-odoo
9395

9496
# Install pyproject-dependencies helper scripts.
9597
ARG build_deps="setuptools-odoo wheel whool"
@@ -155,3 +157,4 @@ ENV INCLUDE=
155157
ENV EXCLUDE=
156158
ENV OCA_GIT_USER_NAME=oca-ci
157159
ENV OCA_GIT_USER_EMAIL=oca-ci@odoo-community.org
160+
ENV OCA_ENABLE_CHECKLOG_ODOO=

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Environment variables:
3838
- `EXCLUDE=`
3939
- `OCA_GIT_USER_NAME=oca-ci`: git user name to commit `.pot` files
4040
- `OCA_GIT_USER_EMAIL=oca-ci@odoo-community.org`: git user email to commit
41+
- `OCA_ENABLE_CHECKLOG_ODOO=`: enable odoo log error checking
4142
`.pot` files
4243

4344
Available commands:
@@ -54,6 +55,7 @@ Available commands:
5455
- `oca_git_push_if_remote_did_not_change`: push local commits unless the remote
5556
tracked branch has evolved.
5657
- `oca_export_and_push_pot` combines the two previous commands.
58+
- `oca_checklog_odoo` checks odoo logs for errors (including warnings)
5759

5860
## Build
5961

bin/oca_checklog_odoo

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
#
4+
# Check if odoo logs contain errors. Assumes logs will come from stdin
5+
#
6+
7+
if [ -n "${OCA_ENABLE_CHECKLOG_ODOO}" ]; then
8+
checklog-odoo
9+
else
10+
cat
11+
fi

bin/oca_init_test_database

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# installed. Use unbuffer to get a colored output.
66
#
77

8-
set -ex
8+
set -exo pipefail
99

1010
oca_wait_for_postgres
1111

@@ -18,4 +18,4 @@ fi
1818
unbuffer $(which odoo) \
1919
-d ${PGDATABASE} \
2020
-i ${ADDONS:-base} \
21-
--stop-after-init
21+
--stop-after-init | oca_checklog_odoo

bin/oca_run_tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Run tests. Use unbuffer to get a colored output.
55
#
66

7-
set -ex
7+
set -exo pipefail
88

99
oca_wait_for_postgres
1010

@@ -18,4 +18,4 @@ unbuffer coverage run --include "${ADDONS_DIR}/*" --branch \
1818
-d ${PGDATABASE} \
1919
-i ${ADDONS} \
2020
--test-enable \
21-
--stop-after-init
21+
--stop-after-init | oca_checklog_odoo

tests/data/addons/addon_warning/__init__.py

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "addon that generates warnings",
3+
"version": "1.0.0",
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_warning
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import logging
2+
from odoo.tests.common import TransactionCase
3+
4+
5+
_logger = logging.getLogger(__name__)
6+
7+
class Test(TransactionCase):
8+
def test_log_warning(self):
9+
_logger.warning("This is a warning")

tests/test_checklog.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import subprocess
3+
from .common import install_test_addons, dropdb, did_run_test_module
4+
5+
6+
def test_checklog_enabled():
7+
"""Test addon_warning with checklog enabled."""
8+
with install_test_addons(["addon_warning"]) as addons_dir:
9+
dropdb()
10+
subprocess.check_call(["oca_init_test_database"], cwd=addons_dir)
11+
os.environ["OCA_ENABLE_CHECKLOG_ODOO"] = "1"
12+
result = subprocess.run(
13+
["oca_run_tests"], cwd=addons_dir, text=True, capture_output=True
14+
)
15+
os.environ["OCA_ENABLE_CHECKLOG_ODOO"] = ""
16+
assert result.returncode == 1 and "Error: Errors detected in log." in result.stderr
17+
18+
def test_checklog_disabled():
19+
"""Test addon_warning with checklog disabled."""
20+
with install_test_addons(["addon_warning"]) as addons_dir:
21+
dropdb()
22+
subprocess.check_call(["oca_init_test_database"], cwd=addons_dir)
23+
result = subprocess.check_output(
24+
["oca_run_tests"], cwd=addons_dir, text=True
25+
)
26+
assert did_run_test_module(result, "addon_warning.tests.test_warning")

0 commit comments

Comments
 (0)