3 """Run the testtools test suite for all supported Pythons.
5 Prints output as a subunit test suite. If anything goes to stderr, that is
6 treated as a test error. If a Python is not available, then it is skipped.
9 from datetime
import datetime
21 from testtools
import (
25 from testtools
.compat
import BytesIO
26 from testtools
.content
import text_content
29 ROOT
= os
.path
.dirname(os
.path
.dirname(__file__
))
32 def run_for_python(version
, result
, tests
):
34 tests
= ['testtools.tests.test_suite']
35 # XXX: This could probably be broken up and put into subunit.
36 python
= 'python%s' % (version
,)
37 # XXX: Correct API, but subunit doesn't support it. :(
38 # result.tags(set(python), set())
40 test
= PlaceHolder(''.join(c
for c
in python
if c
!= '.'))
41 process
= subprocess
.Popen(
42 '%s -c pass' % (python
,), shell
=True,
43 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
46 if process
.returncode
:
47 result
.startTest(test
)
48 result
.addSkip(test
, reason
='%s not available' % (python
,))
52 env
= os
.environ
.copy()
53 if env
.get('PYTHONPATH', None):
54 env
['PYTHONPATH'] = os
.pathsep
.join([ROOT
, env
['PYTHONPATH']])
56 env
['PYTHONPATH'] = ROOT
58 protocol
= TestProtocolServer(result
)
59 subunit_path
= os
.path
.join(os
.path
.dirname(subunit
.__file
__), 'run.py')
62 '-W', 'ignore:Module testtools was already imported',
65 process
= subprocess
.Popen(
66 cmd
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
, env
=env
)
67 _make_stream_binary(process
.stdout
)
68 _make_stream_binary(process
.stderr
)
69 # XXX: This buffers everything. Bad for memory, bad for getting progress
71 output
, error
= process
.communicate()
72 protocol
.readFrom(BytesIO(output
))
74 result
.startTest(test
)
75 result
.addError(test
, details
={
76 'stderr': text_content(error
),
80 # XXX: Correct API, but subunit doesn't support it. :(
81 #result.tags(set(), set(python))
85 return datetime
.utcnow().replace(tzinfo
=iso8601
.Utc())
89 if __name__
== '__main__':
91 result
= TestProtocolClient(sys
.stdout
)
92 for version
in '2.4 2.5 2.6 2.7 3.0 3.1 3.2'.split():
93 run_for_python(version
, result
, sys
.argv
[1:])