Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
pytest 還有他的快樂夥伴
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
joe
August 27, 2014
Programming
220
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
pytest 還有他的快樂夥伴
welcome to Tainan.py:
http://www.meetup.com/Tainan-py-Python-Tainan-User-Group/
joe
August 27, 2014
More Decks by joe
See All by joe
暖場與 Web 相關的小玩具 @ Tainan.py 2013.09.28
excusemejoe
1
220
開場與自我介紹 @ Tainan.py 2013.06.29
excusemejoe
0
70
Taipei.py Logo 的小故事 @ Taipei.py 2013.06.29
excusemejoe
0
230
Bottle Introduction @ Tainan.py 前微聚會
excusemejoe
1
110
PyConTW 2013 Lightning Talk: Bottle vs. Startup
excusemejoe
5
220
Tapei.py Bottle Introduction @2013.03.28
excusemejoe
2
110
Other Decks in Programming
See All in Programming
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
200
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
670
symfony/aiとlaravel/boost
77web
0
120
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
140
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
1k
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
190
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
230
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
240
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
150
Haskell/Servantを通してWebミドルウェアを捉え直す
pizzacat83
0
140
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
820
dRuby over BLE
makicamel
2
400
Featured
See All Featured
Everyday Curiosity
cassininazir
0
250
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Documentation Writing (for coders)
carmenintech
77
5.4k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
220
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
880
The Language of Interfaces
destraynor
162
27k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
760
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
370
Ethics towards AI in product and experience design
skipperchong
2
320
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
660
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Transcript
pytest 還有他的 快樂夥伴 魯蛇喬 @ Taipei.py 2014.08
⼀一般來講 「快樂夥伴」是不重要 的配⾓角們的簡稱 …
他們是值得學習的 今天相反
等等會聊到 … • JUnit • MiniTest • PyUnit (a.k.a. unittest)
• pytest
先假設你看得懂下述魔法:
早就變成潮男(⼥女)了! JUnit 年紀最⼤大的快樂夥伴:
起源 Kent Beck Erich Gamma
最新版的 JUnit
看⼀一下現在怎麼⽤用 JUnit
⼤大量使⽤用 @ annotation Output:
甚⾄至有 @Rule 可取代 before, after ..
None
–肯定句 「現在正在進⾏行 Python 聚會。」
但是 JUnit 還有好多功能 … @theory … 與測試環境/IDE的整合 …
我就是強! 潮男無誤
朝全⽅方位藝⼈人發展 MiniTest 最閃亮的快樂夥伴:
為什麼選他? 2. Ruby 1.9.x bundles minitest not Test::Unit. 1. ⼀一定程度相容
RSpec
有何特⾊色? Unit tests Specs
還有? Benchmark Mock
點到為⽌止、我最簡單 全⽅方位發展
也就是 Python STD 裡⾯面的 unittest PyUnit 最親密的快樂夥伴:
依循著 JUnit 早期的脈絡發展 • 以 3.4.1 為例,基本款功能有: • hooks: setUp/tearDown
… • test discovery 機制 • @unittest.skip /skipif / skipUnless 機制 • 進階款功能: • subtests • 內建 mock
不潮、不多功能 宅男無誤
潮不潮不重要,重點是能夠更好嗎? 少了什麼? ⼀一起想⼀一下:
打得贏 除了unittest以外的 凶殘夥伴嗎? pytest 主⾓角登場:
under certain condition sure
None
No Boilerplate 5. 4. 3. 2. 1.
Assertion: No API & More Pythonic
setUp/tearDown … ? 伊⼈人何處尋
改⽤用 fixture 系統,擁抱 dependency injection 新⼈人換舊⼈人
破除不顯著的時序耦合 1. 4. 3. 2. 我看 報紙才 參數列就知道發⽣生什麼事! #很像 JUnit
的 @Rule 對吧!
可控 fixture 的 scope
清理 fixture
可控 fixture 的 scope
以 fixture 注⼊入另⼀一個 fixture
依照參數⽣生成各種 fixture 且⾃自動注⼊入測試
fixture x fixture
加強版 setUp …
mark 系統
plugins
請參閱官網 tl;r # 或之前在 Tainan.py 分享的 slides
⾃自從有了 pytest 後 ⽤用 Python 寫 tests 可以更快樂 其實
主⾓角打不打得過快樂夥伴不重要 … 結論 # 是否從此對 Testing Framework 更有想法?
True assert QA.time == 0
⼯工商服務:台南.py # 歡迎路過 Tainan.py !
九⽉月⼆二⼗十七⽇日 (六) 下次聚會 # 歡迎路過 Tainan.py !
感謝聆聽 歡迎投稿 # 歡迎路過 Tainan.py !