How to use stdout_text method in avocado

Best Python code snippet using avocado_python

test_io.py

Source:test_io.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Copyright (C) 2012 Anaconda, Inc3# SPDX-License-Identifier: BSD-3-Clause4from __future__ import absolute_import, division, print_function, unicode_literals5from conda.common.io import attach_stderr_handler, captured, CaptureTarget6from io import StringIO7from logging import DEBUG, NOTSET, WARN, getLogger8import sys9def test_captured():10 stdout_text = "stdout text"11 stderr_text = "stderr text"12 def print_captured(*args, **kwargs):13 with captured(*args, **kwargs) as c:14 print(stdout_text, end="")15 print(stderr_text, end="", file=sys.stderr)16 return c17 c = print_captured()18 assert c.stdout == stdout_text19 assert c.stderr == stderr_text20 c = print_captured(CaptureTarget.STRING, CaptureTarget.STRING)21 assert c.stdout == stdout_text22 assert c.stderr == stderr_text23 c = print_captured(stderr=CaptureTarget.STDOUT)24 assert c.stdout == stdout_text + stderr_text25 assert c.stderr is None26 caller_stdout = StringIO()27 caller_stderr = StringIO()28 c = print_captured(caller_stdout, caller_stderr)29 assert c.stdout is caller_stdout30 assert c.stderr is caller_stderr31 assert caller_stdout.getvalue() == stdout_text32 assert caller_stderr.getvalue() == stderr_text33 with captured() as outer_c:34 inner_c = print_captured(None, None)35 assert inner_c.stdout is None36 assert inner_c.stderr is None37 assert outer_c.stdout == stdout_text38 assert outer_c.stderr == stderr_text39def test_attach_stderr_handler():40 name = 'abbacadabba'41 logr = getLogger(name)42 assert len(logr.handlers) == 043 assert logr.level is NOTSET44 debug_message = "debug message 1329-485"45 with captured() as c:46 attach_stderr_handler(WARN, name)47 logr.warn('test message')48 logr.debug(debug_message)49 assert len(logr.handlers) == 150 assert logr.handlers[0].name == 'stderr'51 assert logr.handlers[0].level is WARN52 assert logr.level is NOTSET53 assert c.stdout == ''54 assert 'test message' in c.stderr55 assert debug_message not in c.stderr56 # round two, with debug57 with captured() as c:58 attach_stderr_handler(DEBUG, name)59 logr.warn('test message')60 logr.debug(debug_message)61 logr.info('info message')62 assert len(logr.handlers) == 163 assert logr.handlers[0].name == 'stderr'64 assert logr.handlers[0].level is DEBUG65 assert logr.level is NOTSET66 assert c.stdout == ''67 assert 'test message' in c.stderr...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful