Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5538 Vizualizări

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
5
oct. 16
8784
1
ian. 24
14412
7
iul. 25
50491
0
dec. 24
1327
ODOO.sh Rezolvat
2
oct. 24
13232