← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:buildmaster-duplicate-tests into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:buildmaster-duplicate-tests into launchpad:master.

Commit message:
Avoid duplicating some buildmaster doctests

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/387989

The tests under lib/lp/buildmaster/doc/ were added by both lp.buildmaster.tests.test_buildmaster_documentation and lp.buildmaster.tests.test_doc; this produced some odd effects where giving --load-list input containing any of those test IDs would run each of those tests some-power-of-two times because of each test ID matching itself multiple times from the test list.  Avoid this by merging and simplifying the two test loaders.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:buildmaster-duplicate-tests into launchpad:master.
diff --git a/lib/lp/buildmaster/tests/test_buildmaster_documentation.py b/lib/lp/buildmaster/tests/test_buildmaster_documentation.py
deleted file mode 100644
index d2326aa..0000000
--- a/lib/lp/buildmaster/tests/test_buildmaster_documentation.py
+++ /dev/null
@@ -1,94 +0,0 @@
-# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""Runs the doctests for buildmaster module."""
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-__metaclass__ = type
-
-
-import logging
-import os
-import unittest
-
-from lp.services.config import config
-from lp.testing import (
-    ANONYMOUS,
-    login,
-    logout,
-    )
-from lp.testing.dbuser import switch_dbuser
-from lp.testing.layers import (
-    LaunchpadFunctionalLayer,
-    LaunchpadZopelessLayer,
-    )
-from lp.testing.systemdocs import (
-    LayeredDocFileSuite,
-    setGlobs,
-    setUp,
-    tearDown,
-    )
-
-
-def buildmasterSetUp(test):
-    """Setup a typical builddmaster test environment.
-
-    Log in as ANONYMOUS and perform DB operations as the builddmaster
-    dbuser.
-    """
-    test_dbuser = config.builddmaster.dbuser
-    login(ANONYMOUS)
-    setGlobs(test)
-    test.globs['test_dbuser'] = test_dbuser
-    switch_dbuser(test_dbuser)
-
-
-def buildmasterTearDown(test):
-    logout()
-
-
-special = {
-    'builder.txt': LayeredDocFileSuite(
-        '../doc/builder.txt',
-        setUp=setUp, tearDown=tearDown,
-        layer=LaunchpadFunctionalLayer),
-    'buildqueue.txt': LayeredDocFileSuite(
-        '../doc/buildqueue.txt',
-        setUp=setUp, tearDown=tearDown,
-        layer=LaunchpadFunctionalLayer),
-    }
-
-
-def test_suite():
-    """Load doctests in this directory.
-
-    Use `LayeredDocFileSuite` with the custom `setUp` and tearDown`,
-    suppressed logging messages (only warnings and errors will be posted)
-    on `LaunchpadZopelessLayer`.
-    """
-    suite = unittest.TestSuite()
-    tests_dir = os.path.dirname(os.path.realpath(__file__))
-    docs_dir = tests_dir + "/../doc"
-
-    # Add special tests that do not use the default buildmaster setup
-    # and teardown.
-    for key in sorted(special):
-        suite.addTest(special[key])
-
-    # Add tests using the default buildmaster setup and teardown.
-    filenames = [
-        filename
-        for filename in os.listdir(docs_dir)
-        if filename.lower().endswith('.txt') and filename not in special
-        ]
-
-    for filename in sorted(filenames):
-        test = LayeredDocFileSuite(
-            "../doc/" + filename, setUp=buildmasterSetUp,
-            tearDown=buildmasterTearDown,
-            stdout_logging_level=logging.WARNING,
-            layer=LaunchpadZopelessLayer)
-        suite.addTest(test)
-
-    return suite
diff --git a/lib/lp/buildmaster/tests/test_doc.py b/lib/lp/buildmaster/tests/test_doc.py
index 94f07af..0a1cfd6 100644
--- a/lib/lp/buildmaster/tests/test_doc.py
+++ b/lib/lp/buildmaster/tests/test_doc.py
@@ -1,18 +1,65 @@
-# Copyright 2015-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2020 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-"""Run pagetests."""
+"""Run doctests and pagetests."""
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 
+from lp.services.config import config
 from lp.services.testing import build_test_suite
-from lp.testing.systemdocs import setUp
+from lp.testing import (
+    ANONYMOUS,
+    login,
+    logout,
+    )
+from lp.testing.dbuser import switch_dbuser
+from lp.testing.layers import (
+    LaunchpadFunctionalLayer,
+    LaunchpadZopelessLayer,
+    )
+from lp.testing.systemdocs import (
+    LayeredDocFileSuite,
+    setGlobs,
+    setUp,
+    tearDown,
+    )
 
 
 here = os.path.dirname(os.path.realpath(__file__))
 
 
+def buildmasterSetUp(test):
+    """Setup a typical builddmaster test environment.
+
+    Log in as ANONYMOUS and perform DB operations as the builddmaster
+    dbuser.
+    """
+    test_dbuser = config.builddmaster.dbuser
+    login(ANONYMOUS)
+    setGlobs(test)
+    test.globs['test_dbuser'] = test_dbuser
+    switch_dbuser(test_dbuser)
+
+
+def buildmasterTearDown(test):
+    logout()
+
+
+special = {
+    'builder.txt': LayeredDocFileSuite(
+        '../doc/builder.txt',
+        setUp=setUp, tearDown=tearDown,
+        layer=LaunchpadFunctionalLayer),
+    'buildqueue.txt': LayeredDocFileSuite(
+        '../doc/buildqueue.txt',
+        setUp=setUp, tearDown=tearDown,
+        layer=LaunchpadFunctionalLayer),
+    }
+
+
 def test_suite():
-    return build_test_suite(here, setUp=lambda test: setUp(test, future=True))
+    return build_test_suite(
+        here, special, layer=LaunchpadZopelessLayer,
+        setUp=lambda test: setUp(test, future=True))