İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
5475 Görünümler

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
Vazgeç
En İyi Yanı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.


Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
5
Eki 16
8681
1
Oca 24
14355
7
Tem 25
50374
0
Ara 24
1274
ODOO.sh Çözüldü
2
Eki 24
13158