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
Introduction to pytest
Search
Andreas Pelme
July 23, 2014
Programming
7
1k
Introduction to pytest
Slides for my EuroPython 2014 talk on pytest
Andreas Pelme
July 23, 2014
Tweet
Share
More Decks by Andreas Pelme
See All by Andreas Pelme
pytest: helps you write better Django apps
pelme
5
870
Testing Django applications with py.test (EuroPython 2013)
pelme
2
2.9k
Testing applications Django with py.test (Django Stockholm meetup)
pelme
7
510
Other Decks in Programming
See All in Programming
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
선언형 UI에서의 상태관리
l2hyunwoo
0
150
良いユニットテストを書こう
mototakatsu
5
2k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
220
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
Haze - Real time background blurring
chrisbanes
1
510
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
270
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The Cult of Friendly URLs
andyhume
78
6.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Embracing the Ebb and Flow
colly
84
4.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
2
170
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Fireside Chat
paigeccino
34
3.1k
Transcript
*OUSPEVDUJPOUPQZUFTU "OESFBT1FMNF &VSP1ZUIPO 4MJEFTIUUQTQFBLFSEFDLDPNQFMNF personalkollen
5PQJDT w*OUSPEVDUJPO w5FTUJOHXJUIMFTTCPJMFSQMBUF w1MVHJOT w5FTUEJTDPWFSZ w1ZUFTUpYUVSFT w1PSUJOHFYJTUJOHQSPKFDUT
5FTUJOH
BGVMMGFBUVSFE1ZUIPOUFTUJOHUPPM QZUFTU
None
5FTUTXJUIMFTTCPJMFSQMBUF
%FNPUJNF
%FNP#FGPSF import unittest ! ! def upper_reverse(text):
return ''.join(reversed(text.upper())) ! ! class TestUpperReverse(unittest.TestCase): def test_upper_reverse(self): self.assertEqual(upper_reverse('hello'), 'OLLEH')
%FNP"GUFS def upper_reverse(text): return ''.join(reversed(text.upper()))
! ! def test_upper_reverse(): assert upper_reverse('hello') == 'OLLEH'
%FNPUJNF w"TTFSUJPOTXJUIQMBJOBTTFSUTUBUFNFOU w4VCDMBTTJOH5FTU$BTFJTOPUSFRVJSFE w5FTUTBSFGPVOEBOEDPMMFDUFEXJUIUIF QZUFTUDPNNBOE
1MVHJOT w%JTUSJCVUFEQBSBMMFMJ[FEQZUFTUYEJTU w%KBOHPQZUFTUEKBOHP w5XJTUFEQZUFTUUXJTUFE w-PHDBQUVSFQZUFTUDBQUVSFMPH w$PWFSBHFSFQPSUJOHQZUFTUDPW wBOENBOZNPSF wIUUQQZUFTUPSHMBUFTUQMVHJOTIUNMFYUFSOBMQMVHJOT
3VOOJOHUIFUFTUT
3VOUIFFOUJSFUFTUTVJUF $ py.test
3VOBMMUFTUTJOBTQFDJpDpMF $ py.test test_bar.py
3VOBMMUFTUDBTFTUIBUBSFOBNFE UFTU@GPP $ py.test -‐k test_foo
#ZEFGBVMU QZUFTUEJTDPWFSTUFTUTJO test_*.py *_test.py
.BSLJOHUFTUT ZPVDBONBLFVQZPVSPXONBSLFST import pytest ! ! @pytest.mark.slow def
test_very_long_running_test(): pass
3VOBMMUFTUTXJUIBTQFDJpDNBSLFS $ py.test -‐m slow
PSXJUIPVUBTQFDJpDNBSLFS $ py.test -‐m "not slow"
4LJQQJOHUFTUT import pytest import sys ! ! @pytest.mark.skipif(sys.platform
== 'darwin', reason='Feature Y not supported on OS X') def test_non_osx(): pass
%FQFOEFODZJOKFDUJPOPGUFTUpYUVSFT QZUFTUpYUVSFT
%FNPUJNF
%FQFOEFODZJOKFDUJPOPGUFTUIFMQFS import pytest from selenium.webdriver import Firefox !
@pytest.fixture def webdriver(request): driver = Firefox() request.addfinalizer(driver.quit) return driver ! def test_nix_website_title(webdriver): webdriver.get('https://nixos.org/nix/') assert 'Nix' in webdriver.title ! def test_pytest_website_title(webdriver): webdriver.get('http://pytest.org/latest/')
3VOUFTUTJOGPVSQSPDFTTFT $ pip install pytest-‐xdist $ py.test -‐n 4
VOJUUFTU /PTFTUZMFBOE%KBOHPUFTUTBSFTVQQPSUFE 1PSUJOHBOFYJTUJOHQSPKFDU
"EWBODFE6TFTPGQZUFTU'JYUVSFT 'MPSJT#SVZOPPHIF "! UPEBZ ! *NQSPWJOHZPVSBVUPNBUFEUFTUJOHXJUIQZUFTU )PMHFS,SFLFM ""!'SJEBZ %PO`UNJTT
&NBJMBOESFBT!QFMNFTF 5XJUUFS!BOESFBTQFMNF *3$QFMNF!QZMJCPO'SFFOPEF 4MJEFTIUUQTQFBLFSEFDLDPNQFMNF 2VFTUJPOT