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
360
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
400
Refactoring: la méthode Mikado
ronnix
0
290
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
360
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
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
270
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
220
yield再入門 #phpcon
o0h
PRO
0
350
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
220
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
えっ!!コードを読まずに開発を!?
hananouchi
0
210
symfony/aiとlaravel/boost
77web
0
130
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
110
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.1k
霧の中の代数的エフェクト
funnyycat
1
390
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
130
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Six Lessons from altMBA
skipperchong
29
4.3k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
590
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.8k
Writing Fast Ruby
sferik
630
63k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.6k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Designing Powerful Visuals for Engaging Learning
tmiket
1
450
A Soul's Torment
seathinner
6
3.1k
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 !