Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Techniques de test avancées en Python
Ronan Amicel
September 23, 2017
Programming
0
260
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
290
Refactoring: la méthode Mikado
ronnix
0
210
Product Development in a Startup
ronnix
2
230
Performance des frameworks web : Python vs The World (v1.1)
ronnix
1
7.8k
Je teste mon code avec py.test
ronnix
1
260
Performance des frameworks web : Python vs The World
ronnix
0
240
Introduction au Customer Development
ronnix
1
110
Rendez votre code Python plus beau !
ronnix
1
530
Trompez-vous, et vite !
ronnix
2
150
Other Decks in Programming
See All in Programming
爆速の日経電子版開発の今
shinyaigeek
1
420
ECテックカンファレンス2023
kspace
1
190
OIDC仕様に準拠した Makuake ID連携基盤構築の裏側
ymtdzzz
0
130
eBPF와 함께 이해하는 Cilium 네트워킹
hadaney
3
830
ipa-medit: Memory search and patch tool for IPA without Jailbreaking/ipa-medit-bh2022-europe
tkmru
0
130
Rによる大規模データの処理
s_uryu
2
620
フロントエンドで 良いコードを書くために
t_keshi
3
1.6k
新卒でサービス立ち上げから Hasuraを使って3年経った振り返り
yutorin
0
200
T3 Stack and TypeScript ecosystem
quramy
3
680
様々なWebアプリをAzureにデプロイする
tomokusaba
0
110
Form実装基本を学び直してみた
hyugatsukui
0
230
NGK2023S - OCaml最高! スマホ開発にも使えちゃう?!
haochenxie
0
110
Featured
See All Featured
A Philosophy of Restraint
colly
193
15k
Typedesign – Prime Four
hannesfritz
34
1.5k
YesSQL, Process and Tooling at Scale
rocio
159
12k
The World Runs on Bad Software
bkeepers
PRO
59
5.7k
How New CSS Is Changing Everything About Graphic Design on the Web
jensimmons
214
12k
Atom: Resistance is Futile
akmur
256
24k
Ruby is Unlike a Banana
tanoku
93
9.5k
What's new in Ruby 2.0
geeforr
336
30k
Building Adaptive Systems
keathley
27
1.3k
GraphQLとの向き合い方2022年版
quramy
20
9.8k
Side Projects
sachag
451
37k
Imperfection Machines: The Place of Print at Facebook
scottboms
254
12k
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 !