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
1.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
890
Testing Django applications with py.test (EuroPython 2013)
pelme
2
2.9k
Testing applications Django with py.test (Django Stockholm meetup)
pelme
7
530
Other Decks in Programming
See All in Programming
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
150
AtCoder Heuristic First-step Vol.1 講義スライド(山登り法・焼きなまし法編)
takumi152
3
990
小さく段階的リリースすることで深夜メンテを回避する
mkmk884
2
130
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
350
いまさら聞けない生成AI入門: 「生成AIを高速キャッチアップ」
soh9834
12
3.8k
RailsでCQRS/ESをやってみたきづき
suzukimar
2
1.5k
アーキテクトと美学 / Architecture and Aesthetics
nrslib
12
3.1k
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
370
英語文法から学ぶ、クリーンな設計の秘訣
newnomad
1
270
Coding Experience Cpp vs Csharp - meetup app osaka@9
harukasao
0
120
AI時代のプログラミング教育 / programming education in ai era
kishida
23
21k
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
370
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Agile that works and the tools we love
rasmusluckow
328
21k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
12
1.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
31
4.8k
The Cult of Friendly URLs
andyhume
78
6.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
22
2.6k
Optimizing for Happiness
mojombo
377
70k
KATA
mclloyd
29
14k
Embracing the Ebb and Flow
colly
85
4.6k
How GitHub (no longer) Works
holman
314
140k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
320
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