Best Python code snippet using avocado_python
test_io.py
Source: test_io.py
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...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!