(1) pytest automated testing framework generates test reports (mac system)

Preface

We can use the pytest-html plug-in to generatetest reports, but the test report generated by the pytest-html plug-in is not beautiful enough and not very elegant. It's not high enough. The test report generated through allure is more beautiful and flashy, which can improve it to a higher level.

allure官网: Allure Report Docs — Documentation Overview

allure command line tool installation

Follow the instructions in the official documentation to install the allure command line tool:

1. First download the latest zip file package of allure-commandline:Central Repository: io/qameta/allure/allure-commandline

2. Then extract the zip package to the directory

image

3. Enter the bin directory

image

Notice:

To use allure.bat under window or allure under Linux, you need to add allure to the environment variable.

4. Enter: allure --version at the command line, and the following prompt appears to indicate that allure installation is successful

image

Follow the steps above to install the allure-commandline tool.

Note that the link to download the zip package on the official website is of http protocol. Clicking it will report an error. We can change the protocol from http to https to access the link.

add allure to environment variables

1. Enter the current user directory and execute: open .bash_profile to open a notepad.

image

2. Edit Notepad and enter at the end of the file:

PATH="/usr/local/allure-2.9.0/bin:$PATH"
export PATH

image

3. command+s save

4. Then enter: source .bash_profile in the command line to make the configuration take effect immediately;

5. In any directory, enter allure in the command line. If the following prompt appears, the environment variable configuration is successful;

image

Note: When executing the allure command, jdk support is required. Therefore, the prerequisite for using allure is that jdk is installed in the system and environment variables are configured.

Download and install the allure-pytest plug-in

Enter the command on the command line to install:

  1. pip install -U allure-pytest

After the above command is executed, the allure-pytest and allure-python-commons packages will be installed. These two packages are used to generate the test report data required by allure.

Allure practical application examples
# file_name: test_allure.py
 
 
import pytest
import allure
 
 
@pytest.fixture(scope="function")
def login():
    print("执行登录逻辑")
    yield
    print("执行退出登录逻辑")
 
 
@allure.feature("加入购物车")
def test_01(login):
    """
    先登录,再进行其他操作
    :param login:
    :return:
    """
    print("测试用例01正在执行")
 
 
@allure.feature("加入购物车")
def test_02():
    """
    不需要登录,直接操作
    :return:
    """
    print("测试用例02正在执行")
 
 
if __name__ == '__main__':
    pytest.main(['-s', 'test_allure.py'])

Run the use case, enter the directory where test_allure.py is located, and execute the command:

pytest --alluredir=./report/result    # --alluredir表示指定测试报告数据的生成路径

After executing the above command, a results directory file will be generated in the current directory and the report directory;

Under result is only the raw data of some test reports, which cannot be opened as an html report.

image

To view the test report online, you also need to execute the following command:

allure serve ./report/result

The above command will start an allure service and automatically assign a port, and then use the default browser to automatically open index.html to view the test report:

image

View test report:

image

At this point, we can use pytest combined with allure to generate a more beautiful test report.


              [The following is the most comprehensive software testing engineer learning knowledge architecture system diagram that I have compiled in 2023]


1. Python programming from entry to proficiency

2. Practical implementation of interface automation projects  

3. Web automation project actual combat


4. Practical implementation of App automation project  

5. Resumes of first-tier manufacturers


6. Test and develop DevOps system  

7. Commonly used automated testing tools

8. JMeter performance test  

9. Summary (little surprise at the end of the article)

life is long so add oil. Every effort will not be disappointed, as long as you persevere, you will eventually be rewarded. Cherish your time and pursue your dreams. Don’t forget your original intention and forge ahead. Your future is in your control!

Life is short and time is precious. We cannot predict what will happen in the future, but we can control the present. Cherish every day, work hard, and make yourself stronger and better. With firm belief and persistent pursuit, success will eventually belong to you!

Only by constantly challenging yourself can you constantly surpass yourself. Keep pursuing your dreams and move forward bravely, and you will find that the process of struggle is so beautiful and worthwhile. Believe in yourself, you can do it!​ 

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you!​ 

Guess you like

Origin blog.csdn.net/qq_48811377/article/details/134878312
Recommended