summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2022-11-16 21:25:23 +0000
committerJelmer Vernooij <jelmer@jelmer.uk>2022-11-16 21:25:23 +0000
commite52e3d10c409219479ccfd371f24e3b6d53b73b4 (patch)
treed51ac8c5e22eb98ad4666b0cd6a38285ce3f7ff9
parentaee1c7963691f5523eb72060e53e4ca255a00566 (diff)
downloadsubunit-git-e52e3d10c409219479ccfd371f24e3b6d53b73b4.tar.gz
Fix reading of test lists.fix-test-lists
-rw-r--r--python/subunit/__init__.py8
-rw-r--r--python/subunit/tests/test_filters.py11
2 files changed, 14 insertions, 5 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index 55b0e43..7318a29 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -1252,11 +1252,9 @@ def read_test_list(path):
:param path: Path to the file
:return: Sequence of test ids
"""
- f = open(path, 'rb')
- try:
- return [l.rstrip("\n") for l in f.readlines()]
- finally:
- f.close()
+ with open(path, 'r') as f:
+ return [line.split('#')[0].rstrip() for line in f.readlines()
+ if line.split('#')[0]]
def make_stream_binary(stream):
diff --git a/python/subunit/tests/test_filters.py b/python/subunit/tests/test_filters.py
index 0a5e7c7..bc797da 100644
--- a/python/subunit/tests/test_filters.py
+++ b/python/subunit/tests/test_filters.py
@@ -21,6 +21,17 @@ from testtools import TestCase
from subunit.filters import find_stream
+from subunit import read_test_list
+
+
+class TestReadTestList(TestCase):
+
+ def test_read_list(self):
+ with NamedTemporaryFile() as f:
+ f.write(b'foo\nbar\n# comment\nother # comment\n')
+ f.flush()
+ self.assertEqual(read_test_list(f.name), ['foo', 'bar', 'other'])
+
class TestFindStream(TestCase):