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):
33 # XXX: This could probably be broken up and put into subunit.
34 python = 'python%s' % (version,)
35 # XXX: Correct API, but subunit doesn't support it. :(
36 # result.tags(set(python), set())
38 test = PlaceHolder(''.join(c for c in python if c != '.'))
39 process = subprocess.Popen(
40 '%s -c pass' % (python,), shell=True,
41 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
44 if process.returncode:
45 result.startTest(test)
46 result.addSkip(test, reason='%s not available' % (python,))
50 env = os.environ.copy()
51 if env.get('PYTHONPATH', None):
52 env['PYTHONPATH'] = os.pathsep.join([ROOT, env['PYTHONPATH']])
54 env['PYTHONPATH'] = ROOT
56 protocol = TestProtocolServer(result)
57 subunit_path = os.path.join(os.path.dirname(subunit.__file__), 'run.py')
60 '-W', 'ignore:Module testtools was already imported',
61 subunit_path, 'testtools.tests.test_suite']
62 process = subprocess.Popen(
63 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
64 _make_stream_binary(process.stdout)
65 _make_stream_binary(process.stderr)
66 # XXX: This buffers everything. Bad for memory, bad for getting progress
68 output, error = process.communicate()
69 protocol.readFrom(BytesIO(output))
71 result.startTest(test)
72 result.addError(test, details={
73 'stderr': text_content(error),
77 # XXX: Correct API, but subunit doesn't support it. :(
78 #result.tags(set(), set(python))
82 return datetime.utcnow().replace(tzinfo=iso8601.Utc())
86 if __name__ == '__main__':
88 result = TestProtocolClient(sys.stdout)
89 for version in '2.4 2.5 2.6 2.7 3.0 3.1 3.2'.split():
90 run_for_python(version, result)