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
430
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
概念モデル→論理モデルで気をつけていること
sunnyone
3
300
アプリの "かわいい" を支えるアニメーションツールRiveについて
uetyo
0
280
デザイナーが Androidエンジニアに 挑戦してみた
874wokiite
0
550
Laravel Boost 超入門
fire_arlo
3
220
AIコーディングAgentとの向き合い方
eycjur
0
280
楽して成果を出すためのセルフリソース管理
clipnote
0
190
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
2
1.3k
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
3.3k
RDoc meets YARD
okuramasafumi
4
170
より安全で効率的な Go コードへ: Protocol Buffers Opaque API の導入
shwatanap
2
740
Android端末で実現するオンデバイスLLM 2025
masayukisuda
1
170
複雑なフォームに立ち向かう Next.js の技術選定
macchiitaka
2
220
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
40
2k
Reflections from 52 weeks, 52 projects
jeffersonlam
352
21k
BBQ
matthewcrist
89
9.8k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Producing Creativity
orderedlist
PRO
347
40k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Building Applications with DynamoDB
mza
96
6.6k
Agile that works and the tools we love
rasmusluckow
330
21k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
VelocityConf: Rendering Performance Case Studies
addyosmani
332
24k
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 !