From 9948c7aad6d2de62658e73eba9cf1893d264426e Mon Sep 17 00:00:00 2001 From: Nicholas Riegel Date: Sat, 30 May 2026 02:49:22 -0400 Subject: [PATCH] docs: update CLAUDE.md with Odoo 17 gotchas from K8s test runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix odoo_env fixture pattern to use request.getfixturevalue('env') - Add generate_email → _generate_template migration note - Add conftest.py placement rule (never inside addon package) - Update BDD fixture 'env' not found troubleshooting entry Co-Authored-By: Claude Sonnet 4.6 --- CLAUDE.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9d1a562..990e754 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -313,9 +313,9 @@ from pytest_bdd import scenarios, given, when, then, parsers scenarios('../features/loyalty_discount.feature') # CRITICAL: pytest-bdd scenarios expect 'odoo_env' fixture, not pytest-odoo's 'env'. -# Add this fixture to re-export pytest-odoo's env as odoo_env: +# Use request.getfixturevalue('env') — direct env injection fails in pytest-bdd context: @pytest.fixture -def odoo_env(env): +def odoo_env(request): """pytest-odoo's env fixture, re-exported for BDD step access.""" return env @@ -850,11 +850,13 @@ post = self.env['blog.post'].sudo().create({ | Mail test: `mail.mail.subject` is `False` instead of string | Template subject field not rendered by send_mail() | Verify template fields are populated in DB; render manually if needed | | Odoo 17: `blog.post` doesn't accept `body` or `body_arch` fields | Fields renamed/removed in Odoo 17 | Use factory pattern with `.sudo().create()` to bypass validation; post content should be managed via editor interface, not direct assignment | | Odoo 17: Inverse relationship not loaded in template context | Relations lazy-load; mail.template context may not include reverse relations | Use explicit search in Mako (`for loop`) instead of relying on inverse field; or fetch record with prefetch in the render context | +| Odoo 17: `mail.template` has no `generate_email()` | Method removed in Odoo 17; API changed entirely | Use `template._generate_template([res_id], ['subject', 'body_html'])` — returns `{res_id: {field: value}}`. Never use `generate_email(res_id)` (old Odoo 16 API) | +| conftest.py inside addon dir causes `Invalid import` | pytest adds addon dir to sys.path, bypassing `odoo.addons.*` namespace | Never put conftest.py inside the addon package. Place at repo root or at `/mnt/extra-addons/conftest.py` (parent of addon dir) | | Test: `IndexError: tuple index out of range` when accessing `mock.call_args[0][0]` | Mock method called with keyword-only args; `call_args[0]` is empty tuple `()` | Use `mock.call_args[1].get('key')` for kwargs; or check `mock.called` before accessing `call_args` | | Test: TransactionCase gets `InFailedSqlTransaction` in subsequent tests | Previous test called `self.env.cr.commit()` breaking savepoint chain | Replace `commit()` with `flush_all()` in code being tested; `commit()` is only allowed in non-test code in production | | Test: Mock response returns HTML but code expects JSON | Mock return values must match the data format expected by code under test | Create helper function to generate mocks with correct structure (e.g., JSON string in `.text` field for LLM routers) | | Test: Calling mocked service with wrong parameter name | Test uses different parameter name than actual service signature | Match test calls to actual method signatures (e.g., `topic=` not `prompt=` for LLMRouter.generate()) | -| BDD test: `fixture 'odoo_env' not found` | pytest-bdd scenarios do not automatically map pytest-odoo's `env` fixture | Add `@pytest.fixture def odoo_env(env): return env` wrapper in conftest or test file (section 6.2) | +| BDD test: `fixture 'env' not found` in odoo_env | pytest-bdd cannot inject pytest-odoo's `env` fixture by name into conftest fixtures | Use `request.getfixturevalue('env')` instead of `def odoo_env(env)` — and place the fixture in the BDD test file itself, not only in conftest; conftest in addon dirs triggers import errors | ---