SlideShare a Scribd company logo
nose-parameterized
Speaker: Ben Lee
ben@simplelife.com
Example test with parameterized decorator
import unittest
from nose_parameterized import parameterized
class AddTestCase(unittest.TestCase):
@parameterized.expand([
("2 plus 3", 2, 3, 5),
("3 plus 5", 3, 5, 8),
])
def test_add(self, _, a, b, expected):
self.assertEqual(a + b, expected)
Dynamically created tests
$ nosetests example.py --verbosity=2
test_add_0_2_plus_3 (example.AddTestCase) ... ok
test_add_1_3_plus_5 (example.AddTestCase) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK
Some Use Cases
● Write less code to generate many tests with different parameters
● We use it at SimpleLife to test 15 different scenarios of a django FormWizard
view that has 7-8 steps
○ (given inputs [a,b,c,...], we expect to see [x,y,z,..]
● Use it to test APIs
○ input is JSON blob X, expect JSON blob Y as output
https://github.com/wolever/nose-parameterized
We’re hiring full stack Django devs!

More Related Content

PPTX
Maximal slice problem
PDF
EKON22 Introduction to Machinelearning
PDF
Scoped dynamic rewrite rules
PDF
Clojure LDC 5
PDF
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
ODP
Very basic functional design patterns
DOCX
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
PDF
{:from => 'Java', :to => 'Ruby'}
Maximal slice problem
EKON22 Introduction to Machinelearning
Scoped dynamic rewrite rules
Clojure LDC 5
Асинхронность и многопоточность в Яндекс.Такси — Дмитрий Курилов
Very basic functional design patterns
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
{:from => 'Java', :to => 'Ruby'}

What's hot (20)

PDF
Spock Framework - Slidecast
PDF
Elixir @ Paris.rb
PPTX
Ruby's Arrays and Hashes with examples
DOC
PPTX
Ruby Language: Array, Hash and Iterators
PPTX
Aggregate functions
PDF
Python profiling
PDF
Python 1 liners
PDF
大量地区化解决方案V5
PDF
Annals of Statistics読み回 第一回
TXT
Interfaz Grafica En Java
PPTX
Data mining in Apriori and FP-tree
PPTX
Application of recursive perturbation approach for multimodal optimization
PPTX
Comparative study of algorithms of nonlinear optimization
PDF
03 standard Data Types
PDF
Postgres can do THAT?
PDF
using Queue Server for batch processing
PDF
15 2. arguement passing to main
PDF
Математическая модель системы оценки эффективности реализации программ развит...
PDF
Becoming a better developer with EXPLAIN
Spock Framework - Slidecast
Elixir @ Paris.rb
Ruby's Arrays and Hashes with examples
Ruby Language: Array, Hash and Iterators
Aggregate functions
Python profiling
Python 1 liners
大量地区化解决方案V5
Annals of Statistics読み回 第一回
Interfaz Grafica En Java
Data mining in Apriori and FP-tree
Application of recursive perturbation approach for multimodal optimization
Comparative study of algorithms of nonlinear optimization
03 standard Data Types
Postgres can do THAT?
using Queue Server for batch processing
15 2. arguement passing to main
Математическая модель системы оценки эффективности реализации программ развит...
Becoming a better developer with EXPLAIN
Ad

Viewers also liked (7)

PPTX
Programaçãoproj
PDF
3 jornadas de reflexión la infancia en juego. reflexiones generales
PDF
Aula 3 para acetato
PPTX
aprendizaje colaborativo ventajas.
PDF
Futurismo para Empreendedores @daniel_egger
PDF
7112373 aforismos-de-gurdjieff
PPT
Presentación born espacio coworking
Programaçãoproj
3 jornadas de reflexión la infancia en juego. reflexiones generales
Aula 3 para acetato
aprendizaje colaborativo ventajas.
Futurismo para Empreendedores @daniel_egger
7112373 aforismos-de-gurdjieff
Presentación born espacio coworking
Ad

benpresentation_django

  • 2. Example test with parameterized decorator import unittest from nose_parameterized import parameterized class AddTestCase(unittest.TestCase): @parameterized.expand([ ("2 plus 3", 2, 3, 5), ("3 plus 5", 3, 5, 8), ]) def test_add(self, _, a, b, expected): self.assertEqual(a + b, expected)
  • 3. Dynamically created tests $ nosetests example.py --verbosity=2 test_add_0_2_plus_3 (example.AddTestCase) ... ok test_add_1_3_plus_5 (example.AddTestCase) ... ok ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK
  • 4. Some Use Cases ● Write less code to generate many tests with different parameters ● We use it at SimpleLife to test 15 different scenarios of a django FormWizard view that has 7-8 steps ○ (given inputs [a,b,c,...], we expect to see [x,y,z,..] ● Use it to test APIs ○ input is JSON blob X, expect JSON blob Y as output