How to use dmesg_fail method in avocado

Best Python code snippet using avocado_python Github


Full Screen

1# Copyright (c) 2013 Intel Corporation2#3# Permission is hereby granted, free of charge, to any person obtaining a4# copy of this software and associated documentation files (the "Software"),5# to deal in the Software without restriction, including without limitation6# the rights to use, copy, modify, merge, publish, distribute, sublicense,7# and/or sell copies of the Software, and to permit persons to whom the8# Software is furnished to do so, subject to the following conditions:9#10# The above copyright notice and this permission notice (including the next11# paragraph) shall be included in all copies or substantial portions of the12# Software.13#14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20# IN THE SOFTWARE.21""" Provides classes that represent test statuses22These classes work similar to enums in other languages. They provide a limited23set of attributes that are defined per status:24A name -- a string representation of the values25An integer -- a value that allows classes to be compared using python's rich26comparisons27A tuple representing :28 [0] -- whether the test is considered a passing status29 [1] -- whether the test should be added to the total number of tests. This30 allows statuses like 'skip' to not affect the total percentage.31Status ordering from best to worst:32pass33dmesg-warn34warn35dmesg-fail36fail37timeout38crash39SKIP and NOTRUN are not factored into regressions and fixes, they are counted40seperately. They also derive from a sublcass of Status, which always returns41False42The formula for determining regressions is:43 old_status < new_status44The formula for determining fixes is:45 old_status > new_status46"""47from __future__ import print_function, absolute_import48__all__ = ['NOTRUN',49 'PASS',50 'FAIL',51 'WARN',52 'CRASH',53 'DMESG_WARN',54 'DMESG_FAIL',55 'SKIP',56 'TIMEOUT',57 'ALL']58def status_lookup(status):59 """ Provided a string return a status object instance60 When provided a string that corresponds to a key in it's status_dict61 variable, this function returns a status object instance. If the string62 does not correspond to a key it will raise an exception63 """64 status_dict = {'skip': SKIP,65 'pass': PASS,66 'warn': WARN,67 'fail': FAIL,68 'crash': CRASH,69 'dmesg-warn': DMESG_WARN,70 'dmesg-fail': DMESG_FAIL,71 'notrun': NOTRUN,72 'timeout': TIMEOUT}73 try:74 return status_dict[status]75 except KeyError:76 # Raise a StatusException rather than a key error77 raise StatusException78class StatusException(LookupError):79 """ Raise this exception when a string is passed to status_lookup that80 doesn't exists81 The primary reason to have a special exception is that otherwise82 status_lookup returns a KeyError, but there are many cases where it is83 desireable to except a KeyError and have an exception path. Using a custom84 Error class here allows for more fine-grained control.85 """86 pass87class Status(object):88 """ A simple class for representing the output values of tests.89 This class creatse the necessary magic values to use python's rich90 comparison methods. This allows two objects to be compared using common91 operators like <. >, ==, etc. It also alows them to be looked up in92 containers using ``for x in []`` syntax.93 This class is meant to be immutable, it (ab)uses two tools to provide this94 psuedo-immutability: the property decorator, and the __slots__ attribute to95 1: make the three attributes getters, therefor unwritable, and 2: make96 adding additional attributes impossible97 Arguments:98 name -- the name of the status99 value -- an int used to sort statuses from best to worst (0 -> inf)100 fraction -- a tuple with two ints representing101 [0]: 1 if the status is 'passing', else 0102 [1]: 1 if the status counts toward the total number of tests,103 else 0104 """105 __slots__ = ['__name', '__value', '__fraction']106 def __init__(self, name, value, fraction=(0, 1)):107 assert isinstance(value, int), type(value)108 # The object is immutable, so calling = foo will raise a109 # TypeError. Using setattr from the parrent object works around this.110 self.__name = name111 self.__value = value112 self.__fraction = fraction113 @property114 def name(self):115 """ Return the value of name """116 return self.__name117 @property118 def value(self):119 """ Return the sorting value """120 return self.__value121 @property122 def fraction(self):123 """ Return the totals of the test as a tuple: (<pass>. <total>) """124 return self.__fraction125 def __repr__(self):126 return self.name127 def __str__(self):128 return str( def __unicode__(self):130 return unicode( def __lt__(self, other):132 return not self.__ge__(other)133 def __le__(self, other):134 return not self.__gt__(other)135 def __eq__(self, other):136 # This must be int or status, since status comparisons are done using137 # the __int__ magic method138 if isinstance(other, (int, Status)):139 return int(self) == int(other)140 elif isinstance(other, (str, unicode)):141 return unicode(self) == unicode(other)142 raise TypeError("Cannot compare type: {}".format(type(other)))143 def __ne__(self, other):144 return self.fraction != other.fraction or int(self) != int(other)145 def __ge__(self, other):146 return self.fraction[1] > other.fraction[1] or (147 self.fraction[1] == other.fraction[1] and int(self) >= int(other))148 def __gt__(self, other):149 return self.fraction[1] > other.fraction[1] or int(self) > int(other)150 def __int__(self):151 return self.value152class NoChangeStatus(Status):153 """ Special sublcass of status that overides rich comparison methods154 This special class of a Status is for use with NOTRUN and SKIP, it never155 returns that it is a pass or regression156 """157 def __init__(self, name, value=0, fraction=(0, 0)):158 super(NoChangeStatus, self).__init__(name, value, fraction)159 def __eq__(self, other):160 if isinstance(other, (str, unicode, Status)):161 return unicode(self) == unicode(other)162 raise TypeError("Cannot compare type: {}".format(type(other)))163 def __ne__(self, other):164 if isinstance(other, (str, unicode, Status)):165 return unicode(self) != unicode(other)166 raise TypeError("Cannot compare type: {}".format(type(other)))167NOTRUN = NoChangeStatus('Not Run')168SKIP = NoChangeStatus('skip')169PASS = Status('pass', 0, (1, 1))170WARN = Status('warn', 10)171DMESG_WARN = Status('dmesg-warn', 20)172FAIL = Status('fail', 30)173DMESG_FAIL = Status('dmesg-fail', 40)174TIMEOUT = Status('timeout', 50)175CRASH = Status('crash', 60)176# A tuple (ordered, immutable) of all statuses in this module...

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:


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?