This example describes the Python Automation test run test Cases from the command line with verbosity, to share with you for your reference. Specifically as follows:
The instance file recipe3.py is as follows:
Class Romannumeralconverter (object):
def __init__ (self, roman_numeral):
self.roman_numeral = roman_numeral
Self.digit_map = {"M": 1000, "D": 5, "C": M, "L": +, "X": Ten, "
V": 1}
def convert_to_decimal (self):
val = 0 for
char in self.roman_numeral:
val = + Self.digit_map[char] Return
val
import unittest< C11/>class romannumeralconvertertest (unittest. TestCase):
def Test_parsing_millenia (self):
value = Romannumeralconverter ("M")
self.assertequals ( 1000, Value.convert_to_decimal ())
def Test_parsing_century (self): ' This is an
error test case '
Value = Romannumeralconverter ("C")
self.assertequals (Value.convert_to_decimal ())
if __name__ = = "__ main__ ":
suite = UnitTest. Testloader (). Loadtestsfromtestcase (romannumeralconvertertest)
unittest. Texttestrunner (verbosity=2). Run (Suite)
The results of the operation are shown in the following illustration:
This is how the test case failed.
I hope this article will help you with your Python programming.