python odoo-bin -d <database_name> -i my_module --test-tags=my_module:TestOptimalRouteSelection.test_route_profit_calculation --stop-after-init
-d <database_name>:指定 Odoo 使用的数据库名称。
-i my_module:加载和初始化要测试的模块。
–test-tags=my_module:TestOptimalRouteSelection.test_route_profit_calculation:指定要测试的单个测试用例。
my_module 是模块名称。
TestOptimalRouteSelection 是测试类名称。
test_route_profit_calculation 是测试方法名称。
–stop-after-init:在测试完成后停止 Odoo 实例,便于快速测试
例子:
python odoo-bin -d ma25223 -i ebde_picking_notes --test-tags=ebde_picking_notes:TestPickingOrder.test_picking_order_add_notes
test_picking_notes.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged, Form
from odoo.tests.common import TransactionCase
@tagged('post_install', '-at_install', 'ebde_testings')
class TestPickingOrder(TransactionCase):
def setUp(self):
# CUSTOMER, 默认的一个客户
self.partner_id = self.env['res.partner'].create({
'name': '测试调拨明细说明',
'customer_rank': 1,
'email': 'ru小红hong@163.com',
'phone': '17765852387',
})
self.product_id = self.env['product.product'].create({
'name': '测试调拨说明功能11',
'default_code': 'F05-10-201-4111', # SKU
'type': 'product', # Stockable product
'list_price': 15.0, # Selling price
'standard_price': 10.0, # Cost price
})
# odoo-bin -d ma25223 -i picking_notes --test-tags=picking_notes:TestPickingOrder.test_picking_order_add_notes --stop-after-init
super(TestPickingOrder, self).setUp()
def test_picking_order_add_notes(self):
# Create a sales order
picking_order = self.env['stock.picking'].create({'partner_id': self.partner_id.id, 'picking_type_id': 1,
'origin':'11111',
'move_line_ids_without_package': [(0, 0, {
'product_id': self.product_id.id,
'qty_done': 100,
}),
(0,0, {'name': '3333'})]
})
print('111', picking_order)
# self.assertEqual(picking_order.state, 'done', "Sales order should initially be in draft state.")
pdf_content, _ = self.env['ir.actions.report']._render_qweb_pdf('stock.report_picking', [picking_order.id])
self.assertIn('3333', pdf_content.decode('utf-8'))
# print(self.sale_order.incoterm)
# self.assertIn('Lieferbedingung:', pdf_content.decode('utf-8'))