Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Jerther opened this issue Jul 17, 2024 · 1 comment
Open

Comments

@Jerther
Copy link

Jerther commented Jul 17, 2024

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

@petrus-v
Copy link
Contributor

Could you add more context it's like your TestXXX class is not a subclass of unittest.TestCaseand probably better to use a base Test case class from odoo.tests.common. Could you confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants