Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5513 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 10 16
8743
1
thg 1 24
14384
7
thg 7 25
50411
0
thg 12 24
1309
ODOO.sh Đã xử lý
2
thg 10 24
13196