Merge lp:~allenap/launchpad/sensible-test-ids-for-doctests into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 12734
Proposed branch: lp:~allenap/launchpad/sensible-test-ids-for-doctests
Merge into: lp:launchpad
Diff against target: 63 lines (+12/-4)
3 files modified
lib/canonical/launchpad/testing/systemdocs.py (+8/-0)
lib/canonical/launchpad/testing/tests/test_pages.py (+1/-1)
lib/canonical/launchpad/testing/tests/test_systemdocs.py (+3/-3)
To merge this branch: bzr merge lp:~allenap/launchpad/sensible-test-ids-for-doctests
Reviewer Review Type Date Requested Status
Jonathan Lange (community) Approve
Review via email: mp+55959@code.launchpad.net

Commit message

[r=jml][bug=682771][no-qa] To avoid conflicts, LayeredDocFileSuite now patches test cases to use the filename with path as test ID.

Description of the change

From a new comment in LayeredDocFileSuite:

  DocFileTest insists on using the basename of the file as the test
  ID. This causes conflicts when two doctests have the same filename,
  so we patch the id() method on the test cases.

This branch does not fix the related bug - it does not modify the test
runner - but it does alleviate the symptoms. Something like this is
needed before the linked bug can be fixed in any case.

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

This is awesome. In addition to making parallelizing tests that little bit more effective, you can tweak it just a little to normalize the path that is the docstring id(). That would make "./bin/test -cvvt doc/branch.txt" actually work!

            test.id = lambda: os.path.normpath(repr(test))

Works for me, but you could do something fancier, I guess.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/testing/systemdocs.py'
2--- lib/canonical/launchpad/testing/systemdocs.py 2011-02-17 16:38:15 +0000
3+++ lib/canonical/launchpad/testing/systemdocs.py 2011-04-02 21:29:36 +0000
4@@ -15,6 +15,7 @@
5 ]
6
7 import doctest
8+from functools import partial
9 import logging
10 import os
11 import pdb
12@@ -136,6 +137,13 @@
13 suite = doctest.DocFileSuite(*args, **kw)
14 if layer is not None:
15 suite.layer = layer
16+
17+ # DocFileTest insists on using the basename of the file as the test
18+ # ID. This causes conflicts when two doctests have the same filename, so
19+ # we patch the id() method on the test cases.
20+ for test in suite:
21+ test.id = partial(os.path.normpath, test._dt_test.filename)
22+
23 return suite
24
25
26
27=== modified file 'lib/canonical/launchpad/testing/tests/test_pages.py'
28--- lib/canonical/launchpad/testing/tests/test_pages.py 2010-10-14 19:49:00 +0000
29+++ lib/canonical/launchpad/testing/tests/test_pages.py 2011-04-02 21:29:36 +0000
30@@ -45,7 +45,7 @@
31 bar_test, story = iter_suite_tests(suite)
32
33 # The unnumbered file appears as an independent test.
34- self.assertEqual(os.path.basename(bar_test.id()), 'xx-bar_txt')
35+ self.assertEqual(os.path.basename(bar_test.id()), 'xx-bar.txt')
36
37 # The two numbered tests become a story, which appears as a
38 # single test case rather than a test suite.
39
40=== modified file 'lib/canonical/launchpad/testing/tests/test_systemdocs.py'
41--- lib/canonical/launchpad/testing/tests/test_systemdocs.py 2010-08-20 20:31:18 +0000
42+++ lib/canonical/launchpad/testing/tests/test_systemdocs.py 2011-04-02 21:29:36 +0000
43@@ -61,9 +61,9 @@
44
45 [foo_test, bar_test] = list(suite)
46 self.assertTrue(isinstance(foo_test, unittest.TestCase))
47- self.assertEqual(os.path.basename(foo_test.id()), 'foo_txt')
48+ self.assertEqual(os.path.basename(foo_test.id()), 'foo.txt')
49 self.assertTrue(isinstance(bar_test, unittest.TestCase))
50- self.assertEqual(os.path.basename(bar_test.id()), 'bar_txt')
51+ self.assertEqual(os.path.basename(bar_test.id()), 'bar.txt')
52 self.runSuite(suite, num_tests=2)
53
54 def test_set_layer(self):
55@@ -127,7 +127,7 @@
56 [foo_test] = list(suite)
57 # The test ID and string representation have the prefix
58 # stripped off.
59- self.assertEqual(foo_test.id(), 'foo_txt')
60+ self.assertEqual(foo_test.id(), 'foo.txt')
61 self.assertEqual(str(foo_test), 'foo.txt')
62 # Tests outside of the Launchpad tree root are left as is:
63 config.root = '/nonexistent'