計算機科学のブログ

ほしい物リスト

Python - pytest - Primary Power - Writing Test Functions - field, compare, boolean

Python Testing with pytest, Second Edition - Simple, Rapid, Effective, and ScalableBrian Okken (著)、 Pragmatic Bookshelf のPart Ⅰ(Primary Power)、Chapter 2(Writing Test Functions)、Exercise 2.(98/598)の解答を求めてみる。

入出力結果(Terminal, Zsh)

% source venv/bin/activate
(venv) ... code % pytest exercises/ch2 
============================= test session starts ==============================
platform darwin -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0
rootdir: /Users/.../code
configfile: pytest.ini
collected 7 items                                                              

exercises/ch2/test_card_mod.py ...F...                                   [100%]

=================================== FAILURES ===================================
_________________________ test_equality_with_diff_ids __________________________

    def test_equality_with_diff_ids():
        c1 = Card("something", "brian", "todo", 123)
        c2 = Card("something", "brian", "todo", 4567)
>       assert c1 == c2
E       AssertionError: assert Card(summary=...todo', id=123) == Card(summary=...odo', id=4567)
E         
E         Omitting 3 identical items, use -vv to show
E         Differing attributes:
E         ['id']
E         
E         Drill down into differing attribute id:
E           id: 123 != 4567

exercises/ch2/test_card_mod.py:44: AssertionError
=========================== short test summary info ============================
FAILED exercises/ch2/test_card_mod.py::test_equality_with_diff_ids - AssertionError: assert Card(summary=...todo', id=123) == Card(summary=...od...
========================= 1 failed, 6 passed in 0.04s ==========================
(venv) ... code %