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

What's hot

Spock Framework - Slidecast
Spock Framework - SlidecastSpock Framework - Slidecast
Spock Framework - Slidecast
Daniel Kolman
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
 
Ruby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examplesRuby's Arrays and Hashes with examples
Ruby's Arrays and Hashes with examples
Niranjan Sarade
 
Worst
WorstWorst
Ruby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and IteratorsRuby Language: Array, Hash and Iterators
Ruby Language: Array, Hash and Iterators
Sarah Allen
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
Rosie Jane Enomar
 
Python profiling
Python profilingPython profiling
Python profiling
dreampuf
 
Python 1 liners
Python 1 linersPython 1 liners
Python 1 liners
Nattawut Phetmak
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
bqconf
 
Annals of Statistics読み回 第一回
Annals of Statistics読み回 第一回Annals of Statistics読み回 第一回
Annals of Statistics読み回 第一回
jkomiyama
 
Interfaz Grafica En Java
Interfaz Grafica En JavaInterfaz Grafica En Java
Interfaz Grafica En Java
Řỉgö VẻGầ
 
Data mining in Apriori and FP-tree
Data mining in Apriori and FP-treeData mining in Apriori and FP-tree
Data mining in Apriori and FP-tree
Subhash Rohit
 
Application of recursive perturbation approach for multimodal optimization
Application of recursive perturbation approach for multimodal optimizationApplication of recursive perturbation approach for multimodal optimization
Application of recursive perturbation approach for multimodal optimization
Pranamesh Chakraborty
 
Comparative study of algorithms of nonlinear optimization
Comparative study of algorithms of nonlinear optimizationComparative study of algorithms of nonlinear optimization
Comparative study of algorithms of nonlinear optimization
Pranamesh Chakraborty
 
03 standard Data Types
03 standard Data Types 03 standard Data Types
03 standard Data Types
Ebad ullah Qureshi
 
Postgres can do THAT?
Postgres can do THAT?Postgres can do THAT?
Postgres can do THAT?
alexbrasetvik
 
using Queue Server for batch processing
using Queue Server for batch processingusing Queue Server for batch processing
using Queue Server for batch processing
Ching Yi Chan
 
15 2. arguement passing to main
15 2. arguement passing to main15 2. arguement passing to main
15 2. arguement passing to main
웅식 전
 
Математическая модель системы оценки эффективности реализации программ развит...
Математическая модель системы оценки эффективности реализации программ развит...Математическая модель системы оценки эффективности реализации программ развит...
Математическая модель системы оценки эффективности реализации программ развит...
Anatoly Simkin
 
Becoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINBecoming a better developer with EXPLAIN
Becoming a better developer with EXPLAIN
Louise Grandjonc
 

What's hot (20)

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

Viewers also liked

Programaçãoproj
ProgramaçãoprojProgramaçãoproj
Programaçãoproj
Karensantos
 
3 jornadas de reflexión la infancia en juego. reflexiones generales
3 jornadas de reflexión la infancia en juego. reflexiones generales3 jornadas de reflexión la infancia en juego. reflexiones generales
3 jornadas de reflexión la infancia en juego. reflexiones generales
Jose Angel Gomis
 
Aula 3 para acetato
Aula 3 para acetatoAula 3 para acetato
Aula 3 para acetato
Ana Conceição
 
aprendizaje colaborativo ventajas.
aprendizaje colaborativo ventajas.aprendizaje colaborativo ventajas.
aprendizaje colaborativo ventajas.
Gina Gloria
 
Futurismo para Empreendedores @daniel_egger
Futurismo para Empreendedores @daniel_eggerFuturismo para Empreendedores @daniel_egger
Futurismo para Empreendedores @daniel_egger
Daniel Egger
 
7112373 aforismos-de-gurdjieff
7112373 aforismos-de-gurdjieff7112373 aforismos-de-gurdjieff
7112373 aforismos-de-gurdjieff
Vago Vagales
 
Presentación born espacio coworking
Presentación born espacio coworkingPresentación born espacio coworking
Presentación born espacio coworking
Montserrat Moreno Poza
 

Viewers also liked (7)

Programaçãoproj
ProgramaçãoprojProgramaçãoproj
Programaçãoproj
 
3 jornadas de reflexión la infancia en juego. reflexiones generales
3 jornadas de reflexión la infancia en juego. reflexiones generales3 jornadas de reflexión la infancia en juego. reflexiones generales
3 jornadas de reflexión la infancia en juego. reflexiones generales
 
Aula 3 para acetato
Aula 3 para acetatoAula 3 para acetato
Aula 3 para acetato
 
aprendizaje colaborativo ventajas.
aprendizaje colaborativo ventajas.aprendizaje colaborativo ventajas.
aprendizaje colaborativo ventajas.
 
Futurismo para Empreendedores @daniel_egger
Futurismo para Empreendedores @daniel_eggerFuturismo para Empreendedores @daniel_egger
Futurismo para Empreendedores @daniel_egger
 
7112373 aforismos-de-gurdjieff
7112373 aforismos-de-gurdjieff7112373 aforismos-de-gurdjieff
7112373 aforismos-de-gurdjieff
 
Presentación born espacio coworking
Presentación born espacio coworkingPresentación born espacio coworking
Presentación born espacio coworking
 

Similar to benpresentation_django

Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
Adam Lowry
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
Quintagroup
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
Yeongseon Choe
 
Test Automation Using Googletest
Test Automation Using GoogletestTest Automation Using Googletest
Test Automation Using Googletest
Mohammed_Publications
 
using python module: doctest
using python module: doctestusing python module: doctest
using python module: doctest
mitnk
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
Rainer Schuettengruber
 
Auto testing!
Auto testing!Auto testing!
Auto testing!
Kwangsoo Shin
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
Ray Toal
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
Suraj Deshmukh
 
Python testing
Python  testingPython  testing
Python testing
John(Qiang) Zhang
 
5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis
Franklin Chen
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
outcast96
 
Testing orm based code
Testing orm based codeTesting orm based code
Testing orm based code
Viktor Turskyi
 
Efficient computational modelling for integrated power plant design - Prof Er...
Efficient computational modelling for integrated power plant design - Prof Er...Efficient computational modelling for integrated power plant design - Prof Er...
Efficient computational modelling for integrated power plant design - Prof Er...
UK Carbon Capture and Storage Research Centre
 
Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej PolańczykMock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Pôle Systematic Paris-Region
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
Simon Willison
 
Parametrized testing, v2
Parametrized testing, v2Parametrized testing, v2
Parametrized testing, v2
Brian Okken
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Dr. Volkan OBAN
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Sheeju Alex
 

Similar to benpresentation_django (20)

Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
Intro to Testing in Zope, Plone
Intro to Testing in Zope, PloneIntro to Testing in Zope, Plone
Intro to Testing in Zope, Plone
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
 
Test Automation Using Googletest
Test Automation Using GoogletestTest Automation Using Googletest
Test Automation Using Googletest
 
using python module: doctest
using python module: doctestusing python module: doctest
using python module: doctest
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Auto testing!
Auto testing!Auto testing!
Auto testing!
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Python testing
Python  testingPython  testing
Python testing
 
5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis5-minute intro to property-based testing in Python with hypothesis
5-minute intro to property-based testing in Python with hypothesis
 
PowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdfPowerShell_LangRef_v3 (1).pdf
PowerShell_LangRef_v3 (1).pdf
 
Testing orm based code
Testing orm based codeTesting orm based code
Testing orm based code
 
Efficient computational modelling for integrated power plant design - Prof Er...
Efficient computational modelling for integrated power plant design - Prof Er...Efficient computational modelling for integrated power plant design - Prof Er...
Efficient computational modelling for integrated power plant design - Prof Er...
 
Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej PolańczykMock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
Mock it right! A beginner’s guide to world of tests and mocks, Maciej Polańczyk
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Parametrized testing, v2
Parametrized testing, v2Parametrized testing, v2
Parametrized testing, v2
 
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
Optimization and Mathematical Programming in R and ROI - R Optimization Infra...
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

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