Merge lp:~mrazik/pyruntest/lp1154032 into lp:pyruntest

Proposed by Martin Mrazik
Status: Merged
Approved by: Thomi Richards
Approved revision: 11
Merged at revision: 11
Proposed branch: lp:~mrazik/pyruntest/lp1154032
Merge into: lp:pyruntest
Diff against target: 128 lines (+46/-12)
2 files modified
pyruntest (+16/-10)
tests.py (+30/-2)
To merge this branch: bzr merge lp:~mrazik/pyruntest/lp1154032
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+152905@code.launchpad.net

Commit message

This is introducing a new option for formatted output (-fo) so logging output is not in the xml.

Description of the change

This is introducing a new option for formatted output (-fo) so logging output is not in the xml.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pyruntest'
--- pyruntest 2012-09-14 02:23:55 +0000
+++ pyruntest 2013-03-12 13:06:11 +0000
@@ -22,13 +22,16 @@
2222
2323
24logger = logging.getLogger(__name__)24logger = logging.getLogger(__name__)
25_output_stream = None25_output_descriptors = {
26 '_output_stream': None,
27 '_formatted_output_stream': None
28}
2629
2730
28def main():31def main():
29 args = parse_args()32 args = parse_args()
3033
31 logging.basicConfig(stream=get_output_stream(args))34 logging.basicConfig(stream=get_output_stream(args.output, '_output_stream'))
32 test_suite = load_test_suite_from_name(args.suite)35 test_suite = load_test_suite_from_name(args.suite)
33 runner = construct_test_runner(args)36 runner = construct_test_runner(args)
34 success = runner.run(test_suite).wasSuccessful()37 success = runner.run(test_suite).wasSuccessful()
@@ -36,15 +39,15 @@
36 exit(1)39 exit(1)
3740
3841
39def get_output_stream(args):42def get_output_stream(output, name):
40 global _output_stream43 global _output_descriptors
4144
42 if _output_stream is None:45 if _output_descriptors[name] is None:
43 if args.output:46 if output:
44 _output_stream = open(args.output, 'w')47 _output_descriptors[name] = open(output, 'w')
45 else:48 else:
46 _output_stream = sys.stdout49 _output_descriptors[name] = sys.stdout
47 return _output_stream50 return _output_descriptors[name]
4851
4952
50def patch_python_path():53def patch_python_path():
@@ -110,7 +113,7 @@
110113
111114
112def construct_test_runner(args):115def construct_test_runner(args):
113 output_stream = get_output_stream(args)116 output_stream = get_output_stream(args.formatted_output, '_formatted_output_stream')
114117
115 kwargs = dict(stdout=output_stream,118 kwargs = dict(stdout=output_stream,
116 output_format=args.format119 output_format=args.format
@@ -200,6 +203,9 @@
200 parser.add_argument('-f', '--format', choices=supported_formats.keys(),203 parser.add_argument('-f', '--format', choices=supported_formats.keys(),
201 action=FormatAction, default=supported_formats['text'],204 action=FormatAction, default=supported_formats['text'],
202 help="""Specify what format the test results should be presented in.""")205 help="""Specify what format the test results should be presented in.""")
206 parser.add_argument('-fo', '--formatted-output', type=str,
207 help="""Specify where formatted output (e.g. xml) should go. If left
208 unspecified, stdout is used.""")
203 parser.add_argument('-o', '--output', help="""Specify the location where test209 parser.add_argument('-o', '--output', help="""Specify the location where test
204 output should go. If left unspecified, stdout is used.""")210 output should go. If left unspecified, stdout is used.""")
205 if have_coverage():211 if have_coverage():
206212
=== modified file 'tests.py'
--- tests.py 2012-09-14 02:23:55 +0000
+++ tests.py 2013-03-12 13:06:11 +0000
@@ -36,6 +36,21 @@
36 '''))36 '''))
37 self.addCleanup(remove, 'test_empty.py')37 self.addCleanup(remove, 'test_empty.py')
3838
39 def create_test_file_with_logging(self):
40 open('test_logging.py', 'w').write(dedent('''\
41
42 from testtools import TestCase
43 import logging
44
45 class SimpleTests(TestCase):
46
47 def test_simple(self):
48 logging.error("logging.error")
49 self.assertEqual(1,1)
50
51 '''))
52 self.addCleanup(remove, 'test_logging.py')
53
39 def create_test_package(self):54 def create_test_package(self):
40 location = mkdtemp()55 location = mkdtemp()
41 self.addCleanup(rmtree, location)56 self.addCleanup(rmtree, location)
@@ -87,7 +102,7 @@
87102
88 def test_output_can_be_saved_to_file(self):103 def test_output_can_be_saved_to_file(self):
89 self.create_empty_test_file()104 self.create_empty_test_file()
90 out, err, code = self.run_script('-o', 'test_output', 'test_empty')105 out, err, code = self.run_script('-fo', 'test_output', 'test_empty')
91 self.addCleanup(remove, 'test_output')106 self.addCleanup(remove, 'test_output')
92107
93 self.assertThat(code, Equals(0))108 self.assertThat(code, Equals(0))
@@ -97,7 +112,7 @@
97112
98 def test_output_can_be_saved_to_xml_file(self):113 def test_output_can_be_saved_to_xml_file(self):
99 self.create_empty_test_file()114 self.create_empty_test_file()
100 out, err, code = self.run_script('-o', 'test_output', '-f', 'xml', 'test_empty')115 out, err, code = self.run_script('-fo', 'test_output', '-f', 'xml', 'test_empty')
101 self.addCleanup(remove, 'test_output')116 self.addCleanup(remove, 'test_output')
102117
103 self.assertThat(code, Equals(0))118 self.assertThat(code, Equals(0))
@@ -105,6 +120,19 @@
105 self.assertThat(err, Equals(''))120 self.assertThat(err, Equals(''))
106 self.assertThat(open('test_output').read(), Contains('<testcase classname="test_empty.SimpleTests" name="test_simple"'))121 self.assertThat(open('test_output').read(), Contains('<testcase classname="test_empty.SimpleTests" name="test_simple"'))
107122
123 def test_no_logging_in_xml_file(self):
124 self.create_test_file_with_logging()
125 out, err, code = self.run_script('-fo', 'test_output', '-f', 'xml',
126 'test_logging')
127 self.addCleanup(remove, 'test_output')
128
129 self.assertThat(code, Equals(0))
130 self.assertThat(out, Contains('logging.error'))
131 self.assertThat(err, Equals(''))
132 self.assertThat(open('test_output').read(), Contains('<testcase classname="test_logging.SimpleTests" name="test_simple"'))
133 self.assertThat(open('test_output').read(), Not(Contains('logging.error')))
134
135
108 def test_generates_text_coverage_by_default(self):136 def test_generates_text_coverage_by_default(self):
109 self.create_empty_test_file()137 self.create_empty_test_file()
110 out, err, code = self.run_script('-c', 'test_empty')138 out, err, code = self.run_script('-c', 'test_empty')

Subscribers

People subscribed via source and target branches