Skip to Content

Contributors

Re: odoo13 unittest: installed modules not available while testing

Hi,

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

Can you provide it?

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.

by Simone Orsi - 08:40 - 29 Jul 2021

Reference

  • odoo13 unittest: installed modules not available while testing
    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
    
    
    

    by robert - 05:36 - 28 Jul 2021