def __init__(self, stream=sys.stdout, error_stream=sys.stderr, output_testresult=False, output_summary=True): '''构造函数 :param stream: 指定要输出的流设备 :type stream: file :param output_testresult: 是否输出测试用例执行的日志 :type output_testresult: boolean :param output_summary: 是否输出执行汇总信息 :type output_summary: boolean ''' super(StreamTestReport, self).__init__() self._stream, encoding = ensure_binary_stream(stream) self._err_stream, _ = ensure_binary_stream(error_stream) self._write = lambda x: self._stream.write( smart_binary(x, encoding=encoding)) self._write_err = lambda x: self._err_stream.write( smart_binary(x, encoding=encoding)) self._output_testresult = output_testresult self._output_summary = output_summary self._passed_testresults = [] self._failed_testresults = []
def __init__(self, stream=sys.stdout): '''构造函数 :param stream: 流对象 :type stream: file ''' super(StreamResult, self).__init__() self._stream, encoding = ensure_binary_stream(stream) self._write = lambda x: self._stream.write(smart_binary(x, encoding=encoding)) self._step_results = []
# # Unless required by applicable law or agreed to in writing, software distributed # under the License is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific language # governing permissions and limitations under the License. # '''log模块 ''' import logging import sys import traceback from testbase import context from testbase.util import ensure_binary_stream, smart_binary _stream, _encoding = ensure_binary_stream(sys.stdout) class _Formatter(logging.Formatter): def format(self, record): s = super(_Formatter, self).format(record) return smart_binary(s, encoding=_encoding) _stream_handler = logging.StreamHandler(_stream) _stream_handler.terminator = b"\n" _stream_handler.setFormatter(_Formatter()) class TestResultBridge(logging.Handler): '''中转log信息到TestResult