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
270
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
310
Refactoring: la méthode Mikado
ronnix
0
240
Product Development in a Startup
ronnix
2
240
Performance des frameworks web : Python vs The World (v1.1)
ronnix
1
8k
Je teste mon code avec py.test
ronnix
1
270
Performance des frameworks web : Python vs The World
ronnix
0
310
Introduction au Customer Development
ronnix
1
120
Rendez votre code Python plus beau !
ronnix
1
540
Trompez-vous, et vite !
ronnix
2
210
Other Decks in Programming
See All in Programming
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
2
190
VS Code をプロダクトにどう取り込むか
onomax
1
360
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
190
Code Reviews
bkuhlmann
4
890
Netty Chicago Java User Group 2024-04-17
sullis
0
180
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
490
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
380
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
390
Goのエラースタックトレースの歴史と今後
sonatard
9
1.5k
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
380
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
210
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
370
Featured
See All Featured
Music & Morning Musume
bryan
41
5.6k
Creatively Recalculating Your Daily Design Routine
revolveconf
210
11k
A better future with KSS
kneath
231
16k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
Designing on Purpose - Digital PM Summit 2013
jponch
110
6.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Web development in the modern age
philhawksworth
202
10k
Become a Pro
speakerdeck
PRO
11
4.5k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
78
42k
Web Components: a chance to create the future
zenorocha
305
41k
A Modern Web Designer's Workflow
chriscoyier
689
190k
How to train your dragon (web standard)
notwaldorf
73
5.2k
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 !