Skip to content

Commit

Permalink
- suppress standard output during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dataflake committed Apr 27, 2019
1 parent f583ced commit 2f1362d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Products/PageTemplates/tests/test_persistenttemplate.py
@@ -1,7 +1,9 @@
import io
import re
import unittest

from Products.PageTemplates.ZopePageTemplate import manage_addPageTemplate
from Testing.utils import capture_stdout
from Testing.ZopeTestCase import ZopeTestCase


Expand Down Expand Up @@ -211,7 +213,10 @@ def test_filename_attribute(self):
self.assertEqual(template().strip(), u'012')

def test_edit_with_errors(self):
template = self._makeOne('foo', simple_error)
# Prevent error output to the console
with capture_stdout(io.StringIO()):
template = self._makeOne('foo', simple_error)

# this should not raise:
editable_text = get_editable_content(template)
# and the errors should be in an xml comment at the start of
Expand Down
23 changes: 23 additions & 0 deletions src/Testing/utils.py
@@ -0,0 +1,23 @@
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
""" Some utility functiions for unit tests
"""
import contextlib
import sys

@contextlib.contextmanager
def capture_stdout(file):
old_out = sys.stdout
sys.stdout = file
yield
sys.stdout = old_out

0 comments on commit 2f1362d

Please sign in to comment.