How to parametrize fixtures and test functions
https://docs.pytest.org/en/7.3.x/how-to/parametrize.html
#pytestでパラメタライズテスト
@pytest.mark.parametrize
The builtin pytest.mark.parametrize decorator enables parametrization of arguments for a test function.
3つの組を渡す例。テスト関数は3回実行される
パラメタの値はそのまま渡る(コピーされない)(Note)
リストや辞書を変更する場合、後続のテストの実行では変更されたリストや辞書が使われる
pytest by default escapes any non-ascii characters used in unicode strings for the parametrization because it has several downsides. (Note)
「非アスキー文字はデフォルトでエスケープされる」
エスケープしない設定は disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True だが、望まない副作用の恐れがある
Note that you could also use the parametrize marker on a class or a module
「クラスやモジュールも@pytest.mark.parametrizeでマークできる」
モジュールのときはpytestmarkというグローバル変数らしい
パラメタライズの1つの例 pytest.param でmarksを指定できる
pytest.param("6*9", 42, marks=pytest.mark.xfail)
空のリストが渡されるときの挙動:empty_parameter_set_mark
To get all combinations of multiple parametrized arguments you can stack parametrize decorators:
「重ねることで複数のパラメタ化された引数のすべての組合せを得られる」
code:stack_example.py
@pytest.mark.parametrize("x", 0, 1)
@pytest.mark.parametrize("y", 2, 3)
def test_foo(x, y):
pass
pytest_generate_tests(積ん読)
コマンドラインから渡せるってこと!?
More examples
Parametrizing tests (pytest documentation)