Skip to Content
Pythonによるテスト駆動開発, 3rd Edition
book

Pythonによるテスト駆動開発, 3rd Edition

by Harry Percival
October 2025
Intermediate to advanced
712 pages
9h 46m
Japanese
O'Reilly Media, Inc.
Content preview from Pythonによるテスト駆動開発, 3rd Edition

第26章  トークン社交なやり取り 、ページパターン、 そして読者のための演習

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

「今や全てがソーシャルでなければならない」というジョークは少し時代遅れか? ああ、ハリー。お前がこの本を書き始めた10年前には既に古臭かった。 今では完全に石器時代の遺物だ。 ともあれ、リストは共有した方が良い場合が多いとしよう。 ユーザ同士がリストを共同編集できるようにすべきだ。

その過程で、いわゆる「ページオブジェクトパターン」の実装を始めることで、 我々のFTを改善していく。次に、具体的な手順を明示的に示す代わりに、 単体テストとアプリケーションコードを自分で書いてもらう。 心配するな、合計独りぼっちになるわけじゃない! 取るべき手順の概要と、いくつかのヒントやコツは示す。

とはいえ、まだ経験がないなら、 この章こそが羽ばたくチャンスだ。 楽しんでくれ!

複数ユーザ対応のFTとaddCleanup

さあ始めよう。このFTには2人のユーザが必要だ:

src/functional_tests/test_sharing.py (ch26l001)

from selenium import webdriver
from selenium.webdriver.common.by import By

from .base import FunctionalTest


def quit_if_possible(browser):
    try:
        browser.quit()
    except:
        pass


class SharingTest(FunctionalTest):
    def test_can_share_a_list_with_another_user(self):
        # Edith is a logged-in user
        self.create_pre_authenticated_session("edith@example.com")
        edith_browser = self.browser
        self.addCleanup(lambda: quit_if_possible(edith_browser))

        # Her friend Onesiphorus is also hanging out on the lists site
        oni_browser = webdriver.Firefox()
        self.addCleanup(lambda: quit_if_possible(oni_browser))
        self.browser = oni_browser
        self.create_pre_authenticated_session("onesiphorus@example.com")

        # Edith goes to the home page and starts a list
        self.browser = edith_browser
        self.browser.get(self.live_server_url)
        self.add_list_item("Get help")

        # She notices a "Share this list" option
        share_box = self.browser.find_element(By.CSS_SELECTOR, 'input[name="sharee"]')
        self.assertEqual ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

イーサリアムをマスターする, 2nd Edition

イーサリアムをマスターする, 2nd Edition

Carlo Parisi, Alessandro Mazza, Niccolo Pozzolini, Gavin Wood, Andreas M. Antonopoulos
Excel用Python

Excel用Python

Felix Zumstein

Publisher Resources

ISBN: 0642572274771