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
1=== modified file 'pyruntest'
2--- pyruntest 2012-09-14 02:23:55 +0000
3+++ pyruntest 2013-03-12 13:06:11 +0000
4@@ -22,13 +22,16 @@
5
6
7 logger = logging.getLogger(__name__)
8-_output_stream = None
9+_output_descriptors = {
10+ '_output_stream': None,
11+ '_formatted_output_stream': None
12+}
13
14
15 def main():
16 args = parse_args()
17
18- logging.basicConfig(stream=get_output_stream(args))
19+ logging.basicConfig(stream=get_output_stream(args.output, '_output_stream'))
20 test_suite = load_test_suite_from_name(args.suite)
21 runner = construct_test_runner(args)
22 success = runner.run(test_suite).wasSuccessful()
23@@ -36,15 +39,15 @@
24 exit(1)
25
26
27-def get_output_stream(args):
28- global _output_stream
29+def get_output_stream(output, name):
30+ global _output_descriptors
31
32- if _output_stream is None:
33- if args.output:
34- _output_stream = open(args.output, 'w')
35+ if _output_descriptors[name] is None:
36+ if output:
37+ _output_descriptors[name] = open(output, 'w')
38 else:
39- _output_stream = sys.stdout
40- return _output_stream
41+ _output_descriptors[name] = sys.stdout
42+ return _output_descriptors[name]
43
44
45 def patch_python_path():
46@@ -110,7 +113,7 @@
47
48
49 def construct_test_runner(args):
50- output_stream = get_output_stream(args)
51+ output_stream = get_output_stream(args.formatted_output, '_formatted_output_stream')
52
53 kwargs = dict(stdout=output_stream,
54 output_format=args.format
55@@ -200,6 +203,9 @@
56 parser.add_argument('-f', '--format', choices=supported_formats.keys(),
57 action=FormatAction, default=supported_formats['text'],
58 help="""Specify what format the test results should be presented in.""")
59+ parser.add_argument('-fo', '--formatted-output', type=str,
60+ help="""Specify where formatted output (e.g. xml) should go. If left
61+ unspecified, stdout is used.""")
62 parser.add_argument('-o', '--output', help="""Specify the location where test
63 output should go. If left unspecified, stdout is used.""")
64 if have_coverage():
65
66=== modified file 'tests.py'
67--- tests.py 2012-09-14 02:23:55 +0000
68+++ tests.py 2013-03-12 13:06:11 +0000
69@@ -36,6 +36,21 @@
70 '''))
71 self.addCleanup(remove, 'test_empty.py')
72
73+ def create_test_file_with_logging(self):
74+ open('test_logging.py', 'w').write(dedent('''\
75+
76+ from testtools import TestCase
77+ import logging
78+
79+ class SimpleTests(TestCase):
80+
81+ def test_simple(self):
82+ logging.error("logging.error")
83+ self.assertEqual(1,1)
84+
85+ '''))
86+ self.addCleanup(remove, 'test_logging.py')
87+
88 def create_test_package(self):
89 location = mkdtemp()
90 self.addCleanup(rmtree, location)
91@@ -87,7 +102,7 @@
92
93 def test_output_can_be_saved_to_file(self):
94 self.create_empty_test_file()
95- out, err, code = self.run_script('-o', 'test_output', 'test_empty')
96+ out, err, code = self.run_script('-fo', 'test_output', 'test_empty')
97 self.addCleanup(remove, 'test_output')
98
99 self.assertThat(code, Equals(0))
100@@ -97,7 +112,7 @@
101
102 def test_output_can_be_saved_to_xml_file(self):
103 self.create_empty_test_file()
104- out, err, code = self.run_script('-o', 'test_output', '-f', 'xml', 'test_empty')
105+ out, err, code = self.run_script('-fo', 'test_output', '-f', 'xml', 'test_empty')
106 self.addCleanup(remove, 'test_output')
107
108 self.assertThat(code, Equals(0))
109@@ -105,6 +120,19 @@
110 self.assertThat(err, Equals(''))
111 self.assertThat(open('test_output').read(), Contains('<testcase classname="test_empty.SimpleTests" name="test_simple"'))
112
113+ def test_no_logging_in_xml_file(self):
114+ self.create_test_file_with_logging()
115+ out, err, code = self.run_script('-fo', 'test_output', '-f', 'xml',
116+ 'test_logging')
117+ self.addCleanup(remove, 'test_output')
118+
119+ self.assertThat(code, Equals(0))
120+ self.assertThat(out, Contains('logging.error'))
121+ self.assertThat(err, Equals(''))
122+ self.assertThat(open('test_output').read(), Contains('<testcase classname="test_logging.SimpleTests" name="test_simple"'))
123+ self.assertThat(open('test_output').read(), Not(Contains('logging.error')))
124+
125+
126 def test_generates_text_coverage_by_default(self):
127 self.create_empty_test_file()
128 out, err, code = self.run_script('-c', 'test_empty')

Subscribers

People subscribed via source and target branches