【问题标题】:How to write if condition in python for testcase如何在 python 中为测试用例编写 if 条件
【发布时间】:2023-02-01 17:35:31
【问题描述】:
script: |
      python3 -m coverage erase
      python3 -m coverage run -m pytest tests/ -v --junitxml=junit/test-results.xml --capture=${{ parameters.pytest_capture }}
      TEST_RESULT=$? # Create coverage report even if a test case failed
      python3 -m coverage html
      python3 -m coverage xml
      python3 -m coverage report --show-missing --fail-under=${{ parameters.covFailUnder }} && exit $TEST_RESULT

在 python3 -m coverage run -m pytest 中测试/ -v --junitxml=junit/test-results.xml --capture=${{ parameters.pytest_capture }} tests are running from test folder, i need to make sure to check for both test and unittestcase folder.

那么我该如何编写脚本来阅读两者测试和**单元测试**

我对这些很感兴趣,请提供解决方案

【问题讨论】:

    标签: python


    【解决方案1】:

    这是一个如何做的例子

    def test():
        result = your_function()
        if result == expected_result:
            print("Passed")
        else:
            print("Fail")
    

    另外,您可能需要知道以前是否回答过这个问题:Whats the efficient way to test if-elif-else conditions in python

    【讨论】:

      【解决方案2】:

      要从 tests/ 和 unittests/ 文件夹运行测试,您可以按如下方式修改脚本:

      python3 -m coverage erase
      python3 -m coverage run -m pytest tests/ unittests/ -v --junitxml=junit/test-results.xml --capture=${{ parameters.pytest_capture }}
      TEST_RESULT=$? # Create coverage report even if a test case failed
      python3 -m coverage html
      python3 -m coverage xml
      python3 -m coverage report --show-missing --fail-under=${{ parameters.covFailUnder }} && exit $TEST_RESULT
      

      此处,参数 tests/unittests/ 指定 pytest 应在 tests/ 和 unittests/ 文件夹中搜索测试。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-04
        • 1970-01-01
        • 2021-03-29
        • 2019-05-02
        • 1970-01-01
        • 2016-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多