簡體   English   中英

有沒有辦法在同一個測試中參數化具有多種數據類型的 pytest?

[英]Is there a way to parameterize a pytest with multiple data types in a same test?

目前我有這個實現,我以這種方式運行參數化的 pytest:

@pytest.mark.parametrize('int_val', [1, 0])
   def test_int_val(self, int_val: int):
   # performs all the steps

並以這種方式使用 boolean 值運行相同的測試:

@pytest.mark.parametrize('bool_val', [True, False])
    def test_bool_val(self, bool_val: int):
    # performs all the steps

有沒有辦法將兩個測試結合在一個測試中?

執行以下操作:

@pytest.mark.parametrize('bool_val', [True, False, 1, 0])
def test_bool(bool_val):
    print(f"VAL: {bool_val}")
    # your code

打印這個:

tests/tests_temp.py::test_bool[True] VAL: True
PASSED
tests/tests_temp.py::test_bool[False] VAL: False
PASSED
tests/tests_temp.py::test_bool[1] VAL: 1
PASSED
tests/tests_temp.py::test_bool[0] VAL: 0
PASSED

編輯:根據OP的評論

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM