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
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
260
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
110
MCP with Cloudflare Workers
yusukebe
2
220
testcontainers のススメ
sgash708
1
120
Recoilを剥がしている話
kirik
5
6.8k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
190
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
情報漏洩させないための設計
kubotak
3
340
From Translations to Multi Dimension Entities
alexanderschranz
2
130
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
180
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
7
1.3k
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1366
200k
What's in a price? How to price your products and services
michaelherold
243
12k
Designing Experiences People Love
moore
138
23k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Unsuck your backbone
ammeep
669
57k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
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