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
860
Testing Django applications with py.test (EuroPython 2013)
pelme
2
2.8k
Testing applications Django with py.test (Django Stockholm meetup)
pelme
7
510
Other Decks in Programming
See All in Programming
cmp.Or に感動した
otakakot
3
210
Jakarta EE meets AI
ivargrimstad
0
620
Jakarta EE meets AI
ivargrimstad
0
690
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.8k
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
230
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Remix on Hono on Cloudflare Workers
yusukebe
1
300
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
110
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
C++でシェーダを書く
fadis
6
4.1k
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Teambox: Starting and Learning
jrom
133
8.8k
What's in a price? How to price your products and services
michaelherold
243
12k
Typedesign – Prime Four
hannesfritz
40
2.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
We Have a Design System, Now What?
morganepeng
50
7.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
110
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Speed Design
sergeychernyshev
25
620
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
A Modern Web Designer's Workflow
chriscoyier
693
190k
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