test_parametrize.py
python_old/pytest-workshop/pytest-workshop-solutions/tests/test_parametrize.py
import pytest, json
from src.mathy import add, reciprocal
@pytest.mark.parametrize(
"a,b,expected",
[(1,2,3), (0,0,0), (-1,1,0), (10,-7,3)],
ids=["simple","zeros","cancel","mixed"],
)
def test_add_param(a,b,expected):
assert add(a,b) == expected
@pytest.mark.parametrize("x,expected", [(4,0.25), (2,0.5), (8,0.125)])
def test_reciprocal_param(x, expected):
assert reciprocal(x) == expected
@pytest.fixture
def payload(request):
return json.loads(request.param)
@pytest.mark.parametrize("payload", ['{"x":1}', '{"x":2,"y":3}'], indirect=True)
def test_payload_shape(payload):
assert "x" in payload
관련 글
01_classical_caesar_cipher.py
01_classical_caesar_cipher.py — python source code from the python old learning materials (python_old/Cryptography/01_classical_caesar_cipher.py).
글 읽기 →02_classical_monoalphabetic.py
02_classical_monoalphabetic.py — python source code from the python old learning materials (python_old/Cryptography/02_classical_monoalphabetic.py).
글 읽기 →03_classical_rail_fence.py
03_classical_rail_fence.py — python source code from the python old learning materials (python_old/Cryptography/03_classical_rail_fence.py).
글 읽기 →04_frequency_analysis.py
04_frequency_analysis.py — python source code from the python old learning materials (python_old/Cryptography/04_frequency_analysis.py).
글 읽기 →05_cryptographic_hashing.py
05_cryptographic_hashing.py — python source code from the python old learning materials (python_old/Cryptography/05_cryptographic_hashing.py).
글 읽기 →06_password_hashing.py
06_password_hashing.py — python source code from the python old learning materials (python_old/Cryptography/06_password_hashing.py).
글 읽기 →