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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ronan Amicel
September 23, 2017
Programming
350
0
Share
Techniques de test avancées en Python
Présentation à la conférence PyCon FR à Toulouse le 23 octobre 2017.
Ronan Amicel
September 23, 2017
More Decks by Ronan Amicel
See All by Ronan Amicel
Développeur : ce qu’on ne m’a pas appris à l’école
ronnix
1
390
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.3k
Je teste mon code avec py.test
ronnix
1
350
Performance des frameworks web : Python vs The World
ronnix
0
470
Introduction au Customer Development
ronnix
1
160
Rendez votre code Python plus beau !
ronnix
1
590
Trompez-vous, et vite !
ronnix
2
320
Other Decks in Programming
See All in Programming
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
140
LLM Plugin for Node-REDの利用方法と開発について
404background
0
150
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
6
2.7k
inferと仲良くなる10分間
ryokatsuse
1
300
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
100
[KCD Czech] eBPF Meets the GPU: Future of AI Infra Observability
doniacld
0
130
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
150
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
3
1.4k
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
11k
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
330
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
250
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
560
Believing is Seeing
oripsolob
1
140
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
160
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Amusing Abliteration
ianozsvald
1
190
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Music & Morning Musume
bryan
47
7.2k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
210
Unsuck your backbone
ammeep
672
58k
Tell your own story through comics
letsgokoyo
1
940
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 !