如果你還想從頭學起Pytest,可以看看這個系列的文章哦!
背景
pytest 運作 測試用例生成 allure 報告時,當測試用例名稱修改後重新運作,會保留曆史運作記錄
又或者分開運作兩個測試用例檔案,但是 allure 報告生成目錄是同一個,那麼 allure 報告會同時顯示兩個檔案的測試用例運作情況
咱們來看看這種情況
目錄結構
下面兩個栗子都是這個目錄結構

修改名稱的栗子
test_1.py 的代碼
#!/usr/bin/env python#-*- coding: utf-8 -*-
"""__title__ =
__Time__ = 2020/10/28 11:03
__Author__ = 小鳳梨測試筆記
__Blog__ = https://www.cnblogs.com/poloyy/"""
deftest_1():print("test_1 檔案的測試用例1")deftest_2():print("test_1 檔案的測試用例2")
運作指令
進入該目錄下,cmd 運作
pytet test_1.py --alluredir=./allure
allure 報告
隻有兩條用例
修改後的 test_1.py 的代碼
deftest_11():print("test_1 檔案的測試用例1")deftest_22():print("test_1 檔案的測試用例2")
再次運作指令,檢視 allure 報告
四條用例,包含了曆史的兩條,這不是我們希望看到的
分開運作測試用例檔案的栗子
test_2.py 的代碼
#!/usr/bin/env python#-*- coding: utf-8 -*-
"""__title__ =
__Time__ = 2020/10/28 11:03
__Author__ = 小鳳梨測試筆記
__Blog__ = https://www.cnblogs.com/poloyy/"""
deftest_1():print("test_1 檔案的測試用例1")deftest_2():print("test_1 檔案的測試用例2")
分開運作 test_1 和 test_2 兩個測試用例檔案
#先運作第一個
pytet test_1.py --alluredir=./allure#再運作第二個,此時應該希望 allure 報告隻有 test_2.py 的測試用例
pytet test_2.py --alluredir=./allure
檢視 allure 報告
出現了 test_1.py 的測試用例,這不是想要的結果
--clean-alluredir 參數
前言
pytest 提供了 --clean-alluredir 參數可以清空 allure 報告生成的目錄
可以看看 pytest 的說明文檔
pytest -h
将上面的栗子重新運作
#先運作第一個
pytet test_1.py --alluredir=./allure#再運作第二個,此時應該希望 allure 報告隻有 test_2.py 的測試用例
pytet test_2.py --alluredir=./allure --clean-alluredir
運作結果