changeset 106598cc5f7f in modules/production_work_timesheet:default
details: 
https://hg.tryton.org/modules/production_work_timesheet?cmd=changeset&node=106598cc5f7f
description:
        Replace test setuptools command by unittest discover

        issue9215
        review389851002
diffstat:

 setup.py                                |    6 +-
 tests/__init__.py                       |    8 --
 tests/test_module.py                    |  107 ++++++++++++++++++++++++++++++
 tests/test_production_work_timesheet.py |  113 --------------------------------
 tox.ini                                 |    3 +-
 5 files changed, 112 insertions(+), 125 deletions(-)

diffs (276 lines):

diff -r 2dff37a3bb09 -r 106598cc5f7f setup.py
--- a/setup.py  Sun Apr 10 19:11:39 2022 +0200
+++ b/setup.py  Sat Apr 16 18:30:18 2022 +0200
@@ -138,13 +138,13 @@
     license='GPL-3',
     python_requires='>=3.7',
     install_requires=requires,
+    extras_require={
+        'test': tests_require,
+        },
     dependency_links=dependency_links,
     zip_safe=False,
     entry_points="""
     [trytond.modules]
     production_work_timesheet = trytond.modules.production_work_timesheet
     """,
-    test_suite='tests',
-    test_loader='trytond.test_loader:Loader',
-    tests_require=tests_require,
     )
diff -r 2dff37a3bb09 -r 106598cc5f7f tests/__init__.py
--- a/tests/__init__.py Sun Apr 10 19:11:39 2022 +0200
+++ b/tests/__init__.py Sat Apr 16 18:30:18 2022 +0200
@@ -1,10 +1,2 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
-
-try:
-    from 
trytond.modules.production_work_timesheet.tests.test_production_work_timesheet 
import \
-        suite  # noqa: E501
-except ImportError:
-    from .test_production_work_timesheet import suite
-
-__all__ = ['suite']
diff -r 2dff37a3bb09 -r 106598cc5f7f tests/test_module.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_module.py      Sat Apr 16 18:30:18 2022 +0200
@@ -0,0 +1,107 @@
+# This file is part of Tryton.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+
+import datetime
+
+from trytond.modules.company.tests import (
+    CompanyTestMixin, create_company, create_employee, set_company)
+from trytond.pool import Pool
+from trytond.tests.test_tryton import ModuleTestCase, with_transaction
+
+
+class ProductionWorkTimesheetTestCase(CompanyTestMixin, ModuleTestCase):
+    'Test Production Work Timesheet module'
+    module = 'production_work_timesheet'
+
+    def create_work(self, production_state='draft'):
+        pool = Pool()
+        Work = pool.get('production.work')
+        Operation = pool.get('production.routing.operation')
+        WorkCenter = pool.get('production.work.center')
+        Production = pool.get('production')
+
+        work_center = WorkCenter(name='Work Center')
+        work_center.save()
+
+        operation = Operation(name='Operation')
+        operation.timesheet_available = True
+        operation.save()
+
+        production = Production(state=production_state)
+        production.save()
+
+        work = Work(
+            production=production,
+            operation=operation,
+            work_center=work_center)
+        return work
+
+    @with_transaction()
+    def test_set_timesheet_work(self):
+        'Test _set_timesheet_work'
+        pool = Pool()
+        Work = pool.get('production.work')
+        TimesheetWork = pool.get('timesheet.work')
+        Date = pool.get('ir.date')
+
+        company = create_company()
+        with set_company(company):
+            # Test on create
+            work = self.create_work()
+            work.save()
+            self.assertEqual(len(work.timesheet_works), 1)
+
+            # Test on write
+            work.operation.timesheet_available = False
+            work.operation.save()
+            work.sequence = 1  # trigger write
+            work.save()
+            self.assertFalse(work.timesheet_works)
+
+            # Test delete
+            work = self.create_work()
+            work.save()
+            timesheet_work, = work.timesheet_works
+            timesheet_work_id = timesheet_work.id
+            Work.delete([work])
+            self.assertFalse(
+                TimesheetWork.search([('id', '=', timesheet_work_id)]))
+
+            # Test create as done
+            work = self.create_work(production_state='done')
+            work.save()
+            timesheet_work, = work.timesheet_works
+            self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
+
+            # Set write as done
+            work = self.create_work()
+            work.save()
+            work.state = 'done'
+            work.save()
+            timesheet_work, = work.timesheet_works
+            self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
+
+    @with_transaction()
+    def test_timesheet_lines(self):
+        'Test timesheet_lines'
+        pool = Pool()
+        TimesheetLine = pool.get('timesheet.line')
+
+        company = create_company()
+        with set_company(company):
+            work = self.create_work()
+            work.save()
+
+            employee = create_employee(company)
+
+            timesheet_line = TimesheetLine(
+                employee=employee,
+                duration=datetime.timedelta(1))
+
+            work.timesheet_lines = [timesheet_line]
+            work.save()
+
+            self.assertEqual(len(work.timesheet_lines), 1)
+
+
+del ModuleTestCase
diff -r 2dff37a3bb09 -r 106598cc5f7f tests/test_production_work_timesheet.py
--- a/tests/test_production_work_timesheet.py   Sun Apr 10 19:11:39 2022 +0200
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-# This file is part of Tryton.  The COPYRIGHT file at the top level of
-# this repository contains the full copyright notices and license terms.
-import datetime
-import unittest
-
-from trytond.modules.company.tests import (
-    CompanyTestMixin, create_company, create_employee, set_company)
-from trytond.pool import Pool
-from trytond.tests.test_tryton import ModuleTestCase
-from trytond.tests.test_tryton import suite as test_suite
-from trytond.tests.test_tryton import with_transaction
-
-
-class ProductionWorkTimesheetTestCase(CompanyTestMixin, ModuleTestCase):
-    'Test Production Work Timesheet module'
-    module = 'production_work_timesheet'
-
-    def create_work(self, production_state='draft'):
-        pool = Pool()
-        Work = pool.get('production.work')
-        Operation = pool.get('production.routing.operation')
-        WorkCenter = pool.get('production.work.center')
-        Production = pool.get('production')
-
-        work_center = WorkCenter(name='Work Center')
-        work_center.save()
-
-        operation = Operation(name='Operation')
-        operation.timesheet_available = True
-        operation.save()
-
-        production = Production(state=production_state)
-        production.save()
-
-        work = Work(
-            production=production,
-            operation=operation,
-            work_center=work_center)
-        return work
-
-    @with_transaction()
-    def test_set_timesheet_work(self):
-        'Test _set_timesheet_work'
-        pool = Pool()
-        Work = pool.get('production.work')
-        TimesheetWork = pool.get('timesheet.work')
-        Date = pool.get('ir.date')
-
-        company = create_company()
-        with set_company(company):
-            # Test on create
-            work = self.create_work()
-            work.save()
-            self.assertEqual(len(work.timesheet_works), 1)
-
-            # Test on write
-            work.operation.timesheet_available = False
-            work.operation.save()
-            work.sequence = 1  # trigger write
-            work.save()
-            self.assertFalse(work.timesheet_works)
-
-            # Test delete
-            work = self.create_work()
-            work.save()
-            timesheet_work, = work.timesheet_works
-            timesheet_work_id = timesheet_work.id
-            Work.delete([work])
-            self.assertFalse(
-                TimesheetWork.search([('id', '=', timesheet_work_id)]))
-
-            # Test create as done
-            work = self.create_work(production_state='done')
-            work.save()
-            timesheet_work, = work.timesheet_works
-            self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
-
-            # Set write as done
-            work = self.create_work()
-            work.save()
-            work.state = 'done'
-            work.save()
-            timesheet_work, = work.timesheet_works
-            self.assertEqual(timesheet_work.timesheet_end_date, Date.today())
-
-    @with_transaction()
-    def test_timesheet_lines(self):
-        'Test timesheet_lines'
-        pool = Pool()
-        TimesheetLine = pool.get('timesheet.line')
-
-        company = create_company()
-        with set_company(company):
-            work = self.create_work()
-            work.save()
-
-            employee = create_employee(company)
-
-            timesheet_line = TimesheetLine(
-                employee=employee,
-                duration=datetime.timedelta(1))
-
-            work.timesheet_lines = [timesheet_line]
-            work.save()
-
-            self.assertEqual(len(work.timesheet_lines), 1)
-
-
-def suite():
-    suite = test_suite()
-    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
-            ProductionWorkTimesheetTestCase))
-    return suite
diff -r 2dff37a3bb09 -r 106598cc5f7f tox.ini
--- a/tox.ini   Sun Apr 10 19:11:39 2022 +0200
+++ b/tox.ini   Sat Apr 16 18:30:18 2022 +0200
@@ -2,8 +2,9 @@
 envlist = {py37,py38,py39,py310}-{sqlite,postgresql}
 
 [testenv]
+extras = test
 commands =
-    coverage run --include=.*/production_work_timesheet/* setup.py test
+    coverage run --include=.*/production_work_timesheet/* -m unittest discover 
-s tests
     coverage report --include=.*/production_work_timesheet/* --omit=*/tests/*
 deps =
     coverage

Reply via email to