continue pytest Unit testing framework learning ,pytest Many types of test reports can be generated . Let's learn in this section pytest How to generate test reports .

establish test_calss.py  Test case file , Take testing this file as an example .

#coding=utf-8
class TestClass:
def test_one(self):
x = "this"
assert "h" in x def test_two(self):
x = "hello"
assert x == "hi"

Generate resultlog file

Create a normal result file :

> py.test test_class.py  --resultlog=./log.txt

Generate under specified current path log.txt file , Open file , The contents are as follows :

. test_class.py::TestClass::()::test_one
F test_class.py::TestClass::()::test_two
self = <test_class.TestClass instance at 0x000000000307C788> def test_two(self):
x = "hello"
> assert x == "hi"
E assert 'hello' == 'hi'
E - hello
E + hi test_class.py:11: AssertionError

Generate JunitXML file

> py.test test_class.py  --junitxml=./log.xml

It is also specified to generate... In the current directory log.xml file , Open the file as follows :

<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="1" name="pytest" skips="0" tests="2" time="0.015">
<testcase classname="test_class.TestClass" name="test_one" time="0.0"/>
<testcase classname="test_class.TestClass" name="test_two" time="0.00300002098083">
<failure message="assert &apos;hello&apos; == &apos;hi&apos;
- hello
+ hi">self = &lt;test_class.TestClass instance at 0x000000000309C948&gt; def test_two(self):
x = &quot;hello&quot;
&gt; assert x == &quot;hi&quot;
E assert &apos;hello&apos; == &apos;hi&apos;
E - hello
E + hi test_class.py:11: AssertionError
</failure>
</testcase>
</testsuite>

Create something like this XML What's the use of documents ?  Mainly for convenience Jenkin Or other continuous integration tools .

Creating test cases URL  

> py.test test_class.py  --pastebin=all

Copy the print results and finally generate session-log The test report links to the browser :

https://bpaste.net/show/4815ce13c164

Such a display of results would be very friendly .

Of course , You can also just choose to show faile Test cases for

> py.test test_class.py  --pastebin=failed

Generate html Test report

Of course , More time , We hope pytest Can generate beautiful test reports . This requires installation pytest An extension of --pytest-html.

> pip install pytest-html     #  adopt pip install pytest-html

cmd Execute the test file at the command prompt :

>py.test test_class.py --html=./report.html

Specify to generate... In the current directory report.html file , Open the test file :

Python Unit testing framework pytest -- More articles on generating test reports

  1. Python Unit testing framework pytest 2 -- Generate test reports

    From: https://www.cnblogs.com/fnng/p/4768239.html Python Unit testing framework pytest -- Generate test reports 2015-08-29 00:40 by ...

  2. Python Unit testing framework pytest 4 -- Assertion

    From: https://www.cnblogs.com/fnng/p/4774676.html Python Unit testing framework pytest -- Assertion 2015-08-31 23:57 by Insect division , ...

  3. Python Unit testing framework pytest 3 -- fixtures

    From: https://www.cnblogs.com/fnng/p/4769020.html Python Unit testing framework pytest -- fixtures 2015-08-29 13:05 b ...

  4. Python Unit test framework :pytest

    ( One ) Introduce pytest Is a very mature full-featured Python The test framework , The main features are as follows : 1. Simple and flexible , Easy to use : 2. Support parameterization : 3. Support simple unit testing and complex functional testing , It can also be used to make sele ...

  5. Python Unit testing framework pytest -- Assertion

    For testing , Whether it's functional testing , automated testing , Or unit testing . Generally, a correct expected result will be preset , In the process of test execution, we will get an actual result . The success of the test is to compare the actual results with the expected results . This process of comparison is actually ...

  6. Python Unit testing framework pytest 1 --- How to execute test cases

    From: https://www.cnblogs.com/fnng/p/4765112.html Introduce   pytest It's a mature, fully functional Python Testing tools , Can help you write better programs . It's suitable to be simple ...

  7. Python Unit testing framework pytest -- fixtures

    fixtures Not very good at translation , Can be seen as the outer layer of the sandwich biscuit two biscuits . Usually use setup/teardown To express . It's mainly used to wrap test cases , Why do you need such biscuits ? We use web Take automated testing as an example , for example , A system to be tested ...

  8. 【 turn 】nose-parameterized yes Python The unit testing framework implements parametric extension

    Original address : http://www.cnblogs.com/fnng/p/6580636.html Relatively speaking ,Python The following unit testing framework should be weak and less , In especial Python Self contained unittest The test framework , No ...

  9. [ translate ]PyUnit—Python Unit test framework (1)

    1. Original text and references Link to the original text :http://docs.python.org/2/library/unittest.html# Reference documents : http://pyunit.sourceforge.net/ ...

Random recommendation

  1. C# The use of NotifyIcon Implementation of the taskbar tray menu , Icon flashing effect and bubble prompt

    Many programs only need to run in the background , You don't even need your own application interface .NotifyIcon Provides the display function of the program in the taskbar The program download link is as follows : http://download.csdn.net/detail/u01031 ...

  2. RHEL6.2 Install the CD-ROM installation software under

    Reading guide stay RHEL6.2 Mounting virtual CD-ROM installation software in command line mode may be difficult for many novices , Let me give you a detailed introduction . Let's start with , This tutorial is based on RHEL6.2 Install under version Apache For example . This paper mainly describes the method of mounting the virtual optical drive . Environmental Science : ...

  3. Inversion dp classic

    What do you think , At least use 3^n To do it . but . First define : It can be found that only asking for a' b' Then we can directly conclude that c' So how to ask a' Well //dp seek a', In fact, it's just using [0,n) To update a' ; i < n; i+ ...

  4. HDFS Distributed file system design idea

    HDFS Design objectives 1) Hardware errors are the norm , Data storage needs redundancy . 2) Batch reading of data ,Hadoop Good at data analysis rather than transaction processing . 3) Large data sets . 4) Simple uniform model , Reduce system complexity , The file is written once and read many times , 5 ...

  5. 【 note 】shell The main tools of the game

    shell There are a lot of tools that are very good AIDS . One . The way to self-improvement 1.help / --help : Brief help notes : help Is aimed at shell Help with built-in features , gnu The tools are generally " The program name ...

  6. Spring MVC Use in Swagger2 Build dynamic RESTful API

    When multiple terminals (WEB/ Mobile ) When common business logic is needed , It usually builds  RESTful Style services for multi terminal use . In order to reduce the cost of frequent communication with the corresponding terminal development team , In the beginning, we will create a RESTful API Document ...

  7. Java Self increasing (++) and C The increasing difference in language

    stay Java.c In high-level languages such as language, the role of self increasing and self decreasing is basically the same , It's the variable itself plus or minus one . Now I'll just talk about the auto increment , Self subtraction is similar . Self - increment operator (++), There are two forms of writing , One is before the variable : ++ num; The other is changing ...

  8. MVC3 Project summary

    verification Validation Diverse validation rules http://www.cnblogs.com/xling/archive/2012/07/11/2587002.html The most common way to verify is : On the properties of entities ...

  9. Have to use the efficiency tips let you use Mac It's easier | Mac Tips ( 3、 ... and )

    The content and pictures of the article come from : You know , If copyright is involved , Please contact the author for deletion Articles included in : Fengyun community ( Provide thousands of all kinds of products mac Software download ) 1. Preview for GIF Delete frame We are in the process of making pictures or expression packs for articles , Often need to intercept GIF ...

  10. SSH Report errors

    1.SSH Join in HQL When inquiring , Report errors antlr.collections.AST.getLine()I 2. Baidu found that because struts and hibernate Red has antlr-2.7.2.jar, But two ...