Original Note

Scaling Up Unit Test

  • self_study_notes
  • Original Note
  • Updated: 2026-08-31T10:06:42+08:00
Source Collection
self_study_notes
Source Path
self_study_notes/python software/Automatically Testing/Scaling up Unit Test.md
Type
Original Note
Updated At
2026-08-31T10:06:42+08:00

Scaling Up Unit Test

正文

Parameterising Our Unit Tests

Same test code but with different data

Example

from inflammation.models import daily_mean

@pytest.mark.parametrize(
    "test, expected",
    [
        ([ [0, 0], [0, 0], [0, 0] ], [0, 0]),
        ([ [1, 2], [3, 4], [5, 6] ], [3, 4]),
    ])
def test_daily_mean(test, expected):
    """Test mean function works for array of zeroes and positive integers."""
    npt.assert_array_equal(daily_mean(np.array(test)), np.array(expected))

Check the code coverage

install pytest-cov

python3 -m pip install pytest-cov
python3 -m pytest --cov=inflammation.models tests/test_models.py

which statements are not being tested

python3 -m pytest --cov=inflammation.models --cov-report term-missing tests/test_models.py

Evidence-backed relations

Source Note · Same Topic

切换到中文