【问题标题】:Is it possible to generate Allure report in python-unittest?是否可以在 python-unittest 中生成 Allure 报告?
【发布时间】:2019-12-03 10:01:58
【问题描述】:

我在 Pytest 中找到了魅力报告的解决方案。但我需要在 python-unittest 中生成魅力报告。有可能吗?

【问题讨论】:

    标签: python selenium-webdriver python-unittest allure


    【解决方案1】:
    import sys, os, pytest, subprocess
    
    if __name__ == "__main__":
        #Run allure report of this file, export report to PJ/Reports
        pytest.main(['-s', '-q','--alluredir','path_store_allure_report,'Test.py'])
        #Open allue report via browser
        subprocess.run([r'powershell.exe', r'allure ' + 'serve ' + 'path_store_allure_report'])
    

    我将此代码用于我的 Test_runner.py,它可以在完成代码后在浏览器上导出和打开报告

    【讨论】:

      【解决方案2】:

      通过添加诱惑装饰器

      • @allure.story('故事/需求名称')
      • @allure.feature('功能名称')
      • @allure.testcase("测试用例名称")

      例如

      def test_nameOfTheTest(self):
          with allure.step("Open browser"):
      

      或者你可以使用的定义

      @allure.step("Open application") 
      def open_application(self):
      

      用于运行测试:

      python -m pytest nameOftheFile.py(considering its in the root) --alluredir ./results
      

      得到结果:

      allure serve ./results/
      

      希望对你有帮助

      【讨论】:

      • 正如我正确理解的那样,Rahat 想知道如何使用 unittest 而不是 pytest 来做到这一点
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多