Skip to content

Commit

Permalink
Merge pull request #77 from ForgeFlow/add-checklog-odoo
Browse files Browse the repository at this point in the history
[ADD] oca_checklog_odoo: configurable failure on WARNING log messages
  • Loading branch information
sbidoul authored Sep 30, 2024
2 parents af663c6 + 8dbb91e commit 4d42993
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ RUN apt-get update -qq \

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

# Install pyproject-dependencies helper scripts.
ARG build_deps="setuptools-odoo wheel whool"
Expand Down Expand Up @@ -155,3 +157,4 @@ ENV INCLUDE=
ENV EXCLUDE=
ENV OCA_GIT_USER_NAME=oca-ci
ENV [email protected]
ENV OCA_ENABLE_CHECKLOG_ODOO=
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Environment variables:
- `EXCLUDE=`
- `OCA_GIT_USER_NAME=oca-ci`: git user name to commit `.pot` files
- `[email protected]`: git user email to commit
- `OCA_ENABLE_CHECKLOG_ODOO=`: enable odoo log error checking
`.pot` files

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

## Build

Expand Down
11 changes: 11 additions & 0 deletions bin/oca_checklog_odoo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

#
# Check if odoo logs contain errors. Assumes logs will come from stdin
#

if [ -n "${OCA_ENABLE_CHECKLOG_ODOO}" ]; then
checklog-odoo
else
cat
fi
4 changes: 2 additions & 2 deletions bin/oca_init_test_database
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# installed. Use unbuffer to get a colored output.
#

set -ex
set -exo pipefail

oca_wait_for_postgres

Expand All @@ -18,4 +18,4 @@ fi
unbuffer $(which odoo) \
-d ${PGDATABASE} \
-i ${ADDONS:-base} \
--stop-after-init
--stop-after-init | oca_checklog_odoo
4 changes: 2 additions & 2 deletions bin/oca_run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Run tests. Use unbuffer to get a colored output.
#

set -ex
set -exo pipefail

oca_wait_for_postgres

Expand All @@ -18,4 +18,4 @@ unbuffer coverage run --include "${ADDONS_DIR}/*" --branch \
-d ${PGDATABASE} \
-i ${ADDONS} \
--test-enable \
--stop-after-init
--stop-after-init | oca_checklog_odoo
Empty file.
4 changes: 4 additions & 0 deletions tests/data/addons/addon_warning/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "addon that generates warnings",
"version": "1.0.0",
}
1 change: 1 addition & 0 deletions tests/data/addons/addon_warning/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_warning
9 changes: 9 additions & 0 deletions tests/data/addons/addon_warning/tests/test_warning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import logging
from odoo.tests.common import TransactionCase


_logger = logging.getLogger(__name__)

class Test(TransactionCase):
def test_log_warning(self):
_logger.warning("This is a warning")
26 changes: 26 additions & 0 deletions tests/test_checklog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import subprocess
from .common import install_test_addons, dropdb, did_run_test_module


def test_checklog_enabled():
"""Test addon_warning with checklog enabled."""
with install_test_addons(["addon_warning"]) as addons_dir:
dropdb()
subprocess.check_call(["oca_init_test_database"], cwd=addons_dir)
os.environ["OCA_ENABLE_CHECKLOG_ODOO"] = "1"
result = subprocess.run(
["oca_run_tests"], cwd=addons_dir, text=True, capture_output=True
)
os.environ["OCA_ENABLE_CHECKLOG_ODOO"] = ""
assert result.returncode == 1 and "Error: Errors detected in log." in result.stderr

def test_checklog_disabled():
"""Test addon_warning with checklog disabled."""
with install_test_addons(["addon_warning"]) as addons_dir:
dropdb()
subprocess.check_call(["oca_init_test_database"], cwd=addons_dir)
result = subprocess.check_output(
["oca_run_tests"], cwd=addons_dir, text=True
)
assert did_run_test_module(result, "addon_warning.tests.test_warning")

0 comments on commit 4d42993

Please sign in to comment.