Skip to Content
Menu
This question has been flagged
1 Reply
4263 Views

Hello,


I am currently trying to use Unit Tests on my Odoo.sh project, but I can't seem to find my output in my logs.


My Code:

__init__.py

from . import test_example


test_example.py

# -*- coding: utf-8 -*-

# import unittest
from odoo.tests import common
# import logging

# _logger = logging.getLogg


class TestModule(common.TransactionCase):
    
#     at_install = True
#     post_install = True
    
    def setUp(self):
        super(TestModule, self).setUp()
        #Add Test Setup Code Here
        
        
    def test_data(self):
        #Add Test Code Here
        
        # Create a New Location with the Test
        test_location_1 = self.env['stock.location'].create({
            'name': 'Location_1',
            'usage':'internal'
        })
        
        # Create a Another Location
        test_location_2 = self.env['stock.location'].create({
            'name': 'Location_2',
            'usage':'storage'
        })
        
        # Check if the usage of the two created locations are the same
        
        # Assert functions are used to check whether the operation’s output is True or False
        self.assertEqual(test_location_1.usage, test_location_2.usage, msg='TEST FAILED')
        
    
#     if __name__ == '__main__':
#         unittest.main()



My question is:
How do I print my TEST FAILED message to the logs (Or anywhere else to help me identify the exact location of the error)



Any help is appreciated, thanks.

Avatar
Discard
Best Answer

I might need more information to answer your question. Is your test executed?

You need to start odoo with --test-enable and -i <your_module_with_the_test>. And I would recommend --test-tags <your_module_with_the_test> (only execute tests of your module, but not whole odoo test suite) and maybe -d test_1 --stop-after-init as well (seperate database test run).

Then, in the logs you will see

INFO test_1 odoo.addons.your_module_with_the_test.tests.test_example Starting TestModule.test_data ... 
INFO test_1 odoo.addons.your_module_with_the_test.tests.test_example: ====================================================================== 
ERROR test_1 odoo.addons.your_module_with_the_test.tests.test_example: FAIL: TestModule.test_data
Traceback (most recent call last):
  File "/path/to/your/addons/your_module_with_the_test/tests/test_example.py", line 75, in test_data
    self.assertEqual(test_location_1.usage, test_location_2.usage, msg='TEST FAILED')
AssertionError: 'internal' != 'storage'
- internal
+ storage
 : TEST FAILED 


If this does not help, I might need more information.


Avatar
Discard
Related Posts Replies Views Activity
5
Oct 16
7349
1
Jan 24
12878
0
Dec 24
41
ODOO.sh Solved
2
Oct 24
2590
1
Sep 24
286