← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-test-load-list into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-test-load-list into launchpad:master.

Commit message:
Fix bin/test --load-list on Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/388949
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-test-load-list into launchpad:master.
diff --git a/lib/lp/services/testing/customresult.py b/lib/lp/services/testing/customresult.py
index 5862f84..5476043 100644
--- a/lib/lp/services/testing/customresult.py
+++ b/lib/lp/services/testing/customresult.py
@@ -60,7 +60,8 @@ def filter_tests(list_name, reorder_tests=False):
     """
     def do_filter(tests_by_layer_name):
         # Read the tests, filtering out any blank lines.
-        tests = filter(None, [line.strip() for line in open(list_name, 'rb')])
+        with open(list_name) as f:
+            tests = [line.strip() for line in f if line]
         if reorder_tests:
             tests.sort()
         test_lookup = {}
diff --git a/lib/lp/services/testing/tests/test_customresult.py b/lib/lp/services/testing/tests/test_customresult.py
index 0baf596..0c5c8c3 100644
--- a/lib/lp/services/testing/tests/test_customresult.py
+++ b/lib/lp/services/testing/tests/test_customresult.py
@@ -73,7 +73,7 @@ class TestFilterTests(TestCase):
         layername = 'layer-1'
         testnames = ['d', 'c', 'a']
         suite = self.make_suite()
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name)
             results = do_filter({layername: suite})
@@ -87,7 +87,7 @@ class TestFilterTests(TestCase):
         layername = 'layer-1'
         testnames = ['d', 'c', 'a']
         suite = self.make_suite()
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name, reorder_tests=True)
             results = do_filter({layername: suite})
@@ -98,7 +98,7 @@ class TestFilterTests(TestCase):
         # Tests must be kept in their layer.
         suite1, suite2 = self.make_suites()
         testnames = ['a', 'b', 'c', 'z', 'y', 'x']
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name)
             results = do_filter({'layer1': suite1,
@@ -115,7 +115,7 @@ class TestFilterTests(TestCase):
         layername = 'layer-1'
         testnames = ['1', '2', '3']
         suite = self.make_repeated_suite(testnames)
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name)
             results = do_filter({layername: suite})
@@ -131,7 +131,7 @@ class TestFilterTests(TestCase):
         testnames = ['a', 'b', 'c']
         suite = self.make_suites()[0]
 
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name)
             results = do_filter({'layer1': suite,
@@ -149,7 +149,7 @@ class TestFilterTests(TestCase):
         # If tests have no layer (None) work.
         testnames = ['a', 'b', 'y', 'z']
         suite1, suite2 = self.make_suites()
-        with tempfile.NamedTemporaryFile() as f:
+        with tempfile.NamedTemporaryFile(mode='w+') as f:
             self.writeFile(f, testnames)
             do_filter = filter_tests(f.name)
             results = do_filter({'layer1': suite1,