Как настроить детали с ошибкой утверждения, как добавление таблицы html в детали с помощью pytest- html? - PullRequest
1 голос
/ 06 апреля 2020

Я пытаюсь этот код:

assert 1=2, "<table>....</table>"

таблица не отображается подробно, но строки подробно, как показать html тег с сообщением об ошибке подтверждения

1 Ответ

0 голосов
/ 06 апреля 2020

я утверждаю два файла с помощью difflib и показываю сообщение с htmlcontent

self = <test_assert.TestAssert object at 0x00000178F8534748>

    def test_assert_match(self):


        # with open('c1.json', 'w') as f1:
        #     json.dump(content1,f1, indent =4, sort_keys = True, separators = (',',':'))

        content1 = self.readfile(os.path.join(curr,'1.json'))
        content2 = self.readfile(os.path.join(curr,'2.json'))

>       MyAssert.assertMatch(content1, content2, True)

Testcases\test_assert.py:34: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

expect = ['{', '    "a": "123"', '}'], actual = ['{', '    "a": "123",', '    "b": "22"', '}'], isHtml = True

    @staticmethod
    def assertMatch(expect, actual, isHtml = False):
        msg = ''

        if isHtml:
            d = difflib.HtmlDiff()
            msg = d.make_file(expect,actual)
            with open('diff.html','w') as f:
                f.write(msg)

        else:
            d = difflib.Differ()
            diff = d.compare(expect,actual)
            msg = "\n".join(list(diff))

>       assert expect == actual, msg
E       AssertionError: 
E       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
E                 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
E       
E       <html>
E       
E       <head>
E           <meta http-equiv="Content-Type"
E                 content="text/html; charset=utf-8" />
E           <title></title>
E           <style type="text/css">
E               table.diff {font-family:Courier; border:medium;}
E               .diff_header {background-color:#e0e0e0}
E               td.diff_header {text-align:right}
E               .diff_next {background-color:#c0c0c0}
E               .diff_add {background-color:#aaffaa}
E               .diff_chg {background-color:#ffff77}
E               .diff_sub {background-color:#ffaaaa}
E           </style>
E       </head>
E       
E       <body>
E           
E           <table class="diff" id="difflib_chg_to0__top"
E                  cellspacing="0" cellpadding="0" rules="groups" >
E               <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
E               <colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
E               
E               <tbody>
E                   <tr><td class="diff_next" id="difflib_chg_to0__0"><a href="#difflib_chg_to0__0">f</a></td><td class="diff_header" id="from0_1">1</td><td nowrap="nowrap">{</td><td class="diff_next"><a href="#difflib_chg_to0__0">f</a></td><td class="diff_header" id="to0_1">1</td><td nowrap="nowrap">{</td></tr>
E                   <tr><td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="from0_2">2</td><td nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;"a":&nbsp;"123"</td><td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="to0_2">2</td><td nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;"a":&nbsp;"123"<span class="diff_add">,</span></td></tr>
E                   <tr><td class="diff_next"></td><td class="diff_header"></td><td nowrap="nowrap"></td><td class="diff_next"></td><td class="diff_header" id="to0_3">3</td><td nowrap="nowrap"><span class="diff_add">&nbsp;&nbsp;&nbsp;&nbsp;"b":&nbsp;"22"</span></td></tr>
E                   <tr><td class="diff_next"></td><td class="diff_header" id="from0_3">3</td><td nowrap="nowrap">}</td><td class="diff_next"></td><td class="diff_header" id="to0_4">4</td><td nowrap="nowrap">}</td></tr>
E               </tbody>
E           </table>
E           <table class="diff" summary="Legends">
E               <tr> <th colspan="2"> Legends </th> </tr>
E               <tr> <td> <table border="" summary="Colors">
E                             <tr><th> Colors </th> </tr>
E                             <tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
E                             <tr><td class="diff_chg">Changed</td> </tr>
E                             <tr><td class="diff_sub">Deleted</td> </tr>
E                         </table></td>
E                    <td> <table border="" summary="Links">
E                             <tr><th colspan="2"> Links </th> </tr>
E                             <tr><td>(f)irst change</td> </tr>
E                             <tr><td>(n)ext change</td> </tr>
E                             <tr><td>(t)op</td> </tr>
E                         </table></td> </tr>
E           </table>
E       </body>
E       
E       </html>

Testcases\myAssert.py:50: AssertionError

я хочу показать html в деталях, а не в строках .. enter image description here

...