Skip to content

Commit 23eb660

Browse files
committed
[FIX] queue_job: Restore doctesting.
1 parent d51d615 commit 23eb660

3 files changed

Lines changed: 14 additions & 60 deletions

File tree

queue_job/tests/common.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# Copyright 2019 Camptocamp
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3-
import doctest
4-
import logging
53
import typing
64
from contextlib import contextmanager
75
from itertools import groupby
86
from operator import attrgetter
97
from unittest import TestCase, mock
108

11-
from odoo.tests.case import TestCase as _TestCase
12-
from odoo.tests.common import MetaCase
13-
149
from odoo.addons.queue_job.delay import Graph
1510

1611
# pylint: disable=odoo-addons-relative-import
@@ -411,51 +406,3 @@ def test_export(self):
411406
delayable = mock.MagicMock(name="DelayableBinding")
412407
delayable_cls.return_value = delayable
413408
yield delayable_cls, delayable
414-
415-
416-
class OdooDocTestCase(doctest.DocTestCase, _TestCase, MetaCase("DummyCase", (), {})):
417-
"""
418-
We need a custom DocTestCase class in order to:
419-
- define test_tags to run as part of standard tests
420-
- output a more meaningful test name than default "DocTestCase.runTest"
421-
"""
422-
423-
def __init__(
424-
self, doctest, optionflags=0, setUp=None, tearDown=None, checker=None, seq=0
425-
):
426-
super().__init__(
427-
doctest._dt_test,
428-
optionflags=optionflags,
429-
setUp=setUp,
430-
tearDown=tearDown,
431-
checker=checker,
432-
)
433-
self.test_sequence = seq
434-
435-
def setUp(self):
436-
"""Log an extra statement which test is started."""
437-
super().setUp()
438-
logging.getLogger(__name__).info("Running tests for %s", self._dt_test.name)
439-
440-
441-
def load_doctests(module):
442-
"""
443-
Generates a tests loading method for the doctests of the given module
444-
https://docs.python.org/3/library/unittest.html#load-tests-protocol
445-
"""
446-
447-
def load_tests(loader, tests, ignore):
448-
"""
449-
Apply the 'test_tags' attribute to each DocTestCase found by the DocTestSuite.
450-
Also extend the DocTestCase class trivially to fit the class teardown
451-
that Odoo backported for its own test classes from Python 3.8.
452-
"""
453-
454-
for idx, test in enumerate(doctest.DocTestSuite(module)):
455-
odoo_test = OdooDocTestCase(test, seq=idx)
456-
odoo_test.test_tags = {"standard", "at_install", "queue_job", "doctest"}
457-
tests.addTest(odoo_test)
458-
459-
return tests
460-
461-
return load_tests
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Copyright 2015-2016 Camptocamp SA
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3+
import doctest
4+
5+
from odoo.tests import BaseCase, tagged
36

47
# pylint: disable=odoo-addons-relative-import
58
# we are testing, we want to test as we were an external consumer of the API
69
from odoo.addons.queue_job.jobrunner import channels
710

8-
from .common import load_doctests
911

10-
load_tests = load_doctests(channels)
12+
@tagged("doctest")
13+
class TestDoctest(BaseCase):
14+
def test_doctest(self):
15+
doctest.testmod(channels, exclude_empty=True, raise_on_error=True)

queue_job/tests/test_runner_runner.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Copyright 2015-2016 Camptocamp SA
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
3-
4-
# pylint: disable=odoo-addons-relative-import
5-
# we are testing, we want to test as we were an external consumer of the API
3+
import doctest
64
import os
75

86
from odoo.tests import BaseCase, tagged
97

8+
# pylint: disable=odoo-addons-relative-import
9+
# we are testing, we want to test as we were an external consumer of the API
1010
from odoo.addons.queue_job.jobrunner import runner
1111

12-
from .common import load_doctests
1312

14-
load_tests = load_doctests(runner)
13+
@tagged("doctest")
14+
class TestDoctest(BaseCase):
15+
def test_doctest(self):
16+
doctest.testmod(runner, exclude_empty=True, raise_on_error=True)
1517

1618

1719
@tagged("-at_install", "post_install")

0 commit comments

Comments
 (0)