1

すべてのテストの一般的なメッセージを含む新しいセクションを設定する方法を説明しているスタックオーバーフローの回答は既に認識していますが、特定のモジュールのテストが失敗した場合のみ表示される特別なセクションが必要です。

この背後にある話は、私が行った分析のテストを書いたということです。分析機能をさらに発展させたいと思っていますが、結果が正しいことにはかなりの自信があります。したがって、元のバージョンのすべての結果を pickle 化し、現在の関数での出力を pickle 化された元の出力と比較するテストを作成しました ( test_stability.py)。同僚と私自身を助けるために、テストがtest_stability.py失敗したときに表示されるカスタム メッセージを作成したいと考えています。

したがって、test_stability.py2 つのテストを含むファイルがあります。

#test_stability.py
import pytest

def test_form_stable():
      assert True
    
def test_content_stable():
      assert False

そして、2 つの通常の test を含む別のファイルtest_regular.py:

#test_regular.py
import pytest

def test_first_reg():
      assert True
    
def test_second_reg():
      assert False

理想的には、私の pytest レポートは次のようになります。

collected 4 items

test_stability.py::test_form_stable PASSED
test_stability.py::test_content_stable FAILED
test_regular.py::test_first_reg PASSED
test_regular.py::test_second_reg Failed


============================================= FAILURES =============================================
____________________________________________ test_content_stability ____________________________________________

    def test_content_stability():
>        assert False
E        assert False

test_spam.py:9: AssertionError
____________________________________________ test_second_reg ____________________________________________

    def test_second_reg():
>        assert False
E        assert False

test_spam.py:9: AssertionError
---------------------------------------- My custom section -----------------------------------------
test_stability.py::test_content_stability says:   "My custom message"
================================ 2 failed, 2 passed in 0.07 seconds ================================
4

0 に答える 0