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
Techniques de test avancées en Python
Search
Ronan Amicel
September 23, 2017
Programming
0
340
Techniques de test avancées en Python
Présentation à la conférence PyCon FR à Toulouse le 23 octobre 2017.
Ronan Amicel
September 23, 2017
Tweet
Share
More Decks by Ronan Amicel
See All by Ronan Amicel
Développeur : ce qu’on ne m’a pas appris à l’école
ronnix
1
370
Refactoring: la méthode Mikado
ronnix
0
280
Product Development in a Startup
ronnix
2
280
Performance des frameworks web : Python vs The World (v1.1)
ronnix
1
8.2k
Je teste mon code avec py.test
ronnix
1
340
Performance des frameworks web : Python vs The World
ronnix
0
450
Introduction au Customer Development
ronnix
1
150
Rendez votre code Python plus beau !
ronnix
1
580
Trompez-vous, et vite !
ronnix
2
310
Other Decks in Programming
See All in Programming
atmaCup #23でAIコーディングを活用した話
ml_bear
4
740
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
370
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
200
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.2k
朝日新聞のデジタル版を支えるGoバックエンド ー価値ある情報をいち早く確実にお届けするために
junkiishida
1
360
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
330
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
160
Event Storming
hschwentner
3
1.3k
SourceGeneratorのマーカー属性問題について
htkym
0
140
AI主導でFastAPIのWebサービスを作るときに 人間が構造化すべき境界線
okajun35
0
540
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
560
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
640
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Paper Plane
katiecoart
PRO
0
47k
Designing Powerful Visuals for Engaging Learning
tmiket
0
260
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Between Models and Reality
mayunak
2
230
We Are The Robots
honzajavorek
0
190
AI: The stuff that nobody shows you
jnunemaker
PRO
3
350
GraphQLとの向き合い方2022年版
quramy
50
14k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
67
Transcript
Techniques de test avancées en Python Ronan Amicel @amicel PyCon
FR — 23 septembre 2017 — Toulouse
Ronan Amicel Développeur Consultant Coach technique Startups http://pocketsensei.fr/
Le plan 1. Contrôler l’exécution des tests 2. Mettre en
place le contexte 3. Paramétrer les tests 4. Vérifier ce qui s’est passé
0 Préambule : py.test
$ py.test • Un outil en ligne de commande pour
lancer vos tests : • découverte • exécution • affichage des résultats
import pytest • Un framework pour écrire vos tests •
avec très peu de bla bla • avec un mécanisme de fixtures très flexible
1 Techniques pour contrôler l’exécution des tests
Sélection
Exécuter tous les tests $ py.test
Exécuter seulement certains tests $ py.test tests/unit/ $ py.test toto.py
$ py.test --pyargs mon.module
Un test bien précis $ py.test fichier.py::fonction $ py.test fichier.py::Classe::methode
Seulement les tests dont le nom contient un mot-clé $
py.test -k toto $ py.test -k 'toto or tata'
Collecter les tests uniquement $ py.test --collect-only
Quand les tests sont au rouge
Lancer seulement les tests qui ont échoué la dernière fois
$ py.test --lf $ py.test --last-failed
Lancer d'abord les tests qui ont échoué la dernière fois
$ py.test --ff $ py.test --failed-first
S’arrêter à la première erreur $ py.test -x $ py.test
--exitfirst
Afficher les valeurs des variables locales $ py.test -l $
py.test --showlocals
Basculer sur le débogueur en cas d’erreur $ py.test --pdb
Combo ! $ py.test --ff -x -l --pdb
pytest.ini [pytest] addopts = --ff -x -l --pdb
Plugins
Lancer ses tests en parallèle $ pip install pytest-xdist $
py.test -n4
Couverture de tests $ pip install pytest-cov $ py.test --cov
myproj
tox
pyenv
2 Techniques pour mettre en place le contexte
3 Techniques pour paramétrer les tests
4 Techniques pour vérifier ce qui s'est passé
Voir les exemples sur GitHub https://github.com/ronnix/pyconfr2017/
En savoir plus http://pytest.org/ https://tox.readthedocs.io/ https://github.com/pyenv/pyenv http://hypothesis.readthedocs.io/
Questions ?
Merci !