----- joint use of the test suite python testing framework and test reports allure of pytest

The recent introduction jenkins + python + pytest + allure wrote some automated test cases. Encountered such a scenario: If I create two testing tasks, test tasks 1 contains two test cases test_a.py and test_b.py, test Task 2 contains a test case test_c.py.

I. General operation

I assume that the code directory structure has the following three test cases:

 

 

I then configured to run on top of them jenkins core and show allure above

 

 

 

note: the above \ autotest \ target \ allure-results need to specify the directory in the local jenkins good directory.

 

build and found the following results:

 

 test_a.py and test_b.py, test_c.py belong to the same test suite example02.

II. Suite generate different, separate and display different suite

First, prepare the following directory structure:

 

Jenkins then modify the configuration is as follows:

 

 

 

 Such reports have generated two sets of tests.

 

Summary: pytest feeling in the test suite is a test file directory corresponding to a test suite. And testng do not like, you can easily add the test class into a suit.xml file. We can choose according to different tasks, so as to produce a different suite files.

 III. Example To use to store all of this performed by a new file test.py

1. Method a: by way pytest.main

However, this approach must be placed in a non-test_ _test beginning or the end of the py file can be placed testrun.py file. For example, there is a testrun.py:

import pytest


if __name__ == '__main__':
    pytest.main(["-s", "test_a.py", "test_b.py"])

这样testrun.py运行后就会执行test_a.py和test_b.py两个用例

2.方法二:通过新建pytest用例,来存储本次要执行的测试用例,比如test_all.py,在里头需要执行5个测试用例test_a.py,test_b.py,test_c.py,test_d.py,test_e.py

test_all.py中的实现如下:

 

from src.example02.test_a import *
from src.example02.test_b import *
from src.example02.test_c import *
from src.example03.test_d import *
from src.example03.test_e import *

 

 build结束后:

 

 可以发现,test_all.py就是我们的测试套,它包含了5个测试用例。这就可以不同的测试任务对应不同的测试套,不同对的测试套下面可以放各种组合的用例。一个用例可以放在不同的测试套中。

 

原创文章,转载请注明出处!(写的是核心的配置、代码,如有不懂,欢迎留言交流)

Guess you like

Origin www.cnblogs.com/Hermioner/p/12032101.html