Skip to content

AttributeError: 'TestCaseFunction' object has no attribute 'addSubTest'. #69

@Jerther

Description

@Jerther

Hello!

pyTest 7.4.4
pytest-odoo 1.0.0

For any test that is decorated with @tests.users such as:

from odoo import tests

...

@tests.users('demo')
def test_xxx(self):
    self.fail()

The tests actually runs with the specified user as self.env.user but the assertion failures always raise an additional AttributeError:

    @tests.users('demo')
    def test_xxx(self):
>       self.fail()
E       AssertionError: None

tests/test_xxx.py:52: AssertionError

During handling of the above exception, another exception occurred:

func = <function TestXXX.test_xxx at 0x7ff1a697e5f0>
args = (<odoo.addons.some_addon.tests.test_xxx.TestXXX testMethod=test_xxx>,)
kwargs = {}
self = <odoo.addons.some_addon.tests.test_xxx.TestXXX testMethod=test_xxx>
old_uid = 1, Users = res.users(), user_id = {'demo': 3}
login = 'demo'

    @decorator
    def _users(func, *args, **kwargs):
        self = args[0]
        old_uid = self.uid
        try:
            # retrieve users
            Users = self.env['res.users'].with_context(active_test=False)
            user_id = {
                user.login: user.id
                for user in Users.search([('login', 'in', list(logins))])
            }
            for login in logins:
>               with self.subTest(login=login):

../../odoo/odoo/tests/common.py:1919: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.10/contextlib.py:153: in __exit__
    self.gen.throw(typ, value, traceback)
/usr/lib64/python3.10/contextlib.py:153: in __exit__
    self.gen.throw(typ, value, traceback)
E   AttributeError: 'TestCaseFunction' object has no attribute 'addSubTest'. Did you mean: 'addSuccess'?

Not a huge deal, but having to scroll up to the actual assertion error is a bit anoying ;) Can this be fixed?

Something related to subtests has been mentioned in #67

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions