Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: odoo13 unittest: installed modules not available while testing

by
robert
- 29/07/2021 10:29:24
Thanks Simone
On 29.07.21 08:42, Simone Orsi wrote:
Hi,

without your test class it is hard to guess what's wrong ;)

Can you provide it?
Here it is, with some explanations

import base64
from odoo.tests import common
"""
# started with:
bin/odoo -c etc/odoo.cfg
# stopped in the debugger:
self.env.cr.dbname
'odoo13'
self.env['hr.payroll.structure']
hr.payroll.structure()
# started with:
bin/odoo -c etc/odoo.cfg -u aba_connector --test-enable --stop-after-ini
# stopped in the debugger:
self.env.cr.dbname
'odoo13'
self.env['hr.payroll.structure']
Traceback (most recent call last):
Debug Console, prompt 80, line 1
import base64
File "/home/robert/projects/odoo13/odoo13/downloads/odoo-13.0.post20201211/odoo/api.py", line 463, in __getitem__
return self.registry[model_name]._browse(self, (), ())
File "/home/robert/projects/odoo13/odoo13/downloads/odoo-13.0.post20201211/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
builtins.KeyError: 'hr.payroll.structure'
"""
class TestEmployee(common.TransactionCase):
def setUp(self):
# add env on cls and many other things
super(TestEmployee, self).setUp()
user_id = self.env["res.users"].search([])[0].id
emp = self.env["hr.employee"].search(
[("name", "=", "Abigail Peterson")]
) # demo data
if not emp:
emp = self.env["hr.employee"].search([("user_id", "=", 2)])
if not emp:
emp = self.env["hr.employee"].create({"user_id": user_id, "name": "Fritz"})
self.emp = emp
def test_can_open(self):
records = self.env["hr.employee"].search([])
# payroll is installed
# nevertheless the following line crashes
# if I add that same line outside of a test
# it loads fine
structure = self.env["hr.payroll.structure"] # <------------------- dies
assert records

Bests

On Wed, Jul 28, 2021 at 5:37 PM robert@redo2oo.ch <robert@redo2oo.ch> wrote:
Hi there

I try to add some functionality to the payroll.

Now when I try to access the payroll stuff from within a test like so:

self.env['hr.payroll.structure']

I get a traceback:

Traceback (most recent call last):
   Debug Console, prompt 68, line 1
     import base64
   File 
"/home/robert/projects/odoo13/odoo13/downloads/odoo-13.0.post20201211/odoo/api.py", 
line 463, in __getitem__
     return self.registry[model_name]._browse(self, (), ())
   File 
"/home/robert/projects/odoo13/odoo13/downloads/odoo-13.0.post20201211/odoo/modules/registry.py", 
line 177, in __getitem__
     return self.models[model_name]
builtins.KeyError: 'hr.payroll.structure'

However, when I do exactly the same when not being in a unittest, everything 
works fine.

What could be the reason?

I am running on an ubuntu:

Distributor ID:    Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:    focal

using Python:

python
Python 3.8.2 (default, Feb 25 2020, 13:04:52)
[GCC 9.2.1 20200224] on linux

thanks for your input

Robert


_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe



--
Simone Orsi

Full stack Python web developer, Odoo specialist, Odoo Community Board Member, in love with open source.

_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe