計算機科学のブログ

ほしい物リスト

Python - pytest - Primary Power - Writing Test Functions - selecting a testfunctionality, missing

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

コード

exercises/ch2/test_card_mod.py

def test_inequality():
    c1 = Card("something", "brian", "todo", 123)
    c2 = Card("completely different", "okken", "done", 123)
    assert c1 != c2
    c1 = Card("something", "brian", "todo", 123)
    c2 = Card("different", "brian", "todo", 123)
    assert c1 != c2
    c1 = Card("something", "brian", "todo", 123)
    c2 = Card("something", "bdifferent", "todo", 123)
    assert c1 != c2
    c1 = Card("something", "brian", "todo", 123)
    c2 = Card("something", "brian", "different", 123)
    assert c1 != c2

入出力結果(Terminal, Zsh)

% 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 .......                                   [100%]

============================== 7 passed in 0.01s ===============================
% pytest exercises/ch2 -k ine
============================= 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 / 6 deselected / 1 selected                                  

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

======================= 1 passed, 6 deselected in 0.00s ========================
% pytest exercises/ch2 -vv -k ine
============================= test session starts ==============================
platform darwin -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0 -- /Users/.../code/venv/bin/python3.13
cachedir: .pytest_cache
rootdir: /Users/.../code
configfile: pytest.ini
collected 7 items / 6 deselected / 1 selected                                  

exercises/ch2/test_card_mod.py::test_inequality PASSED                   [100%]

======================= 1 passed, 6 deselected in 0.00s ========================
% pytest exercises/ch2 -v -k ine 
============================= test session starts ==============================
platform darwin -- Python 3.13.3, pytest-8.3.5, pluggy-1.6.0 -- /Users/.../code/venv/bin/python3.13
cachedir: .pytest_cache
rootdir: /Users/.../code
configfile: pytest.ini
collected 7 items / 6 deselected / 1 selected                                  

exercises/ch2/test_card_mod.py::test_inequality PASSED                   [100%]

======================= 1 passed, 6 deselected in 0.00s ========================
%