Skip to content

Commit

Permalink
[ADD] Test for oca_checklog_odoo
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloEForgeFlow committed Sep 16, 2024
1 parent bebddf2 commit 50fa884
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
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 50fa884

Please sign in to comment.