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
330
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
360
Refactoring: la méthode Mikado
ronnix
0
270
Product Development in a Startup
ronnix
2
270
Performance des frameworks web : Python vs The World (v1.1)
ronnix
1
8.2k
Je teste mon code avec py.test
ronnix
1
330
Performance des frameworks web : Python vs The World
ronnix
0
440
Introduction au Customer Development
ronnix
1
150
Rendez votre code Python plus beau !
ronnix
1
570
Trompez-vous, et vite !
ronnix
2
310
Other Decks in Programming
See All in Programming
Register is more than clipboard
satorunooshie
1
480
AI 時代だからこそ抑えたい「価値のある」PHP ユニットテストを書く技術 #phpconfuk / phpcon-fukuoka-2025
shogogg
1
550
開発生産性が組織文化になるまでの軌跡
tonegawa07
0
170
Eloquentを使ってどこまでコードの治安を保てるのか?を新人が考察してみた
itokoh0405
0
3.2k
Agentに至る道 〜なぜLLMは自動でコードを書けるようになったのか〜
mackee
5
1.7k
CloudflareのSandbox SDKを試してみた
syumai
0
160
自動テストを活かすためのテスト分析・テスト設計の進め方/JaSST25 Shikoku
goyoki
3
700
スタートアップを支える技術戦略と組織づくり
pospome
6
3.6k
What's New in Web AI?
christianliebel
PRO
0
130
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
210
組織もソフトウェアも難しく考えない、もっとシンプルな考え方で設計する #phpconfuk
o0h
PRO
10
4.5k
AIの弱点、やっぱりプログラミングは人間が(も)勉強しよう / YAPC AI and Programming
kishida
9
5k
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
527
40k
Typedesign – Prime Four
hannesfritz
42
2.9k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Practical Orchestrator
shlominoach
190
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Building Applications with DynamoDB
mza
96
6.8k
Visualization
eitanlees
150
16k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
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 !