From 3b0a28285e20e2a4304f87697f15ef563334b8c0 Mon Sep 17 00:00:00 2001
From: Yannick Tivisse <yti@odoo.com>
Date: Thu, 7 Nov 2019 12:38:29 +0000
Subject: [PATCH] [IMP] delivery: Avoid multi-executed tests

---
 .../delivery/tests/test_packing_delivery.py   | 30 +++++++++++--------
 addons/stock/tests/test_packing.py            |  8 +++--
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/addons/delivery/tests/test_packing_delivery.py b/addons/delivery/tests/test_packing_delivery.py
index 17f4c2edb252..c40cdb2d500c 100644
--- a/addons/delivery/tests/test_packing_delivery.py
+++ b/addons/delivery/tests/test_packing_delivery.py
@@ -1,30 +1,34 @@
-from odoo.addons.stock.tests.test_packing import TestPacking
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
 
+from odoo.addons.stock.tests.test_packing import TestPackingCommon
 
-class TestPacking(TestPacking):
 
-    def setUp(self):
-        super(TestPacking, self).setUp()
-        self.uom_kg = self.env.ref('uom.product_uom_kgm')
-        self.product_aw = self.env['product.product'].create({
+class TestPacking(TestPackingCommon):
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestPacking, cls).setUpClass()
+        cls.uom_kg = cls.env.ref('uom.product_uom_kgm')
+        cls.product_aw = cls.env['product.product'].create({
             'name': 'Product AW',
             'type': 'product',
             'weight': 2.4,
-            'uom_id': self.uom_kg.id,
-            'uom_po_id': self.uom_kg.id
+            'uom_id': cls.uom_kg.id,
+            'uom_po_id': cls.uom_kg.id
         })
-        self.product_bw = self.env['product.product'].create({
+        cls.product_bw = cls.env['product.product'].create({
             'name': 'Product BW',
             'type': 'product',
             'weight': 0.3,
-            'uom_id': self.uom_kg.id,
-            'uom_po_id': self.uom_kg.id
+            'uom_id': cls.uom_kg.id,
+            'uom_po_id': cls.uom_kg.id
         })
-        test_carrier_product = self.env['product.product'].create({
+        test_carrier_product = cls.env['product.product'].create({
             'name': 'Test carrier product',
             'type': 'service',
         })
-        self.test_carrier = self.env['delivery.carrier'].create({
+        cls.test_carrier = cls.env['delivery.carrier'].create({
             'name': 'Test carrier',
             'delivery_type': 'fixed',
             'product_id': test_carrier_product.id,
diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py
index 440ebac31fc9..fba6bfe24734 100644
--- a/addons/stock/tests/test_packing.py
+++ b/addons/stock/tests/test_packing.py
@@ -5,10 +5,11 @@ from odoo.tests.common import SavepointCase
 from odoo.tools import float_round
 
 
-class TestPacking(SavepointCase):
+class TestPackingCommon(SavepointCase):
+
     @classmethod
     def setUpClass(cls):
-        super(TestPacking, cls).setUpClass()
+        super(TestPackingCommon, cls).setUpClass()
         cls.stock_location = cls.env.ref('stock.stock_location_stock')
         cls.warehouse = cls.env['stock.warehouse'].search([('lot_stock_id', '=', cls.stock_location.id)], limit=1)
         cls.warehouse.write({'delivery_steps': 'pick_pack_ship'})
@@ -19,6 +20,9 @@ class TestPacking(SavepointCase):
         cls.productA = cls.env['product.product'].create({'name': 'Product A', 'type': 'product'})
         cls.productB = cls.env['product.product'].create({'name': 'Product B', 'type': 'product'})
 
+
+class TestPacking(TestPackingCommon):
+
     def test_put_in_pack(self):
         """ In a pick pack ship scenario, create two packs in pick and check that
         they are correctly recognised and handled by the pack and ship picking.
-- 
GitLab