SlideShare a Scribd company logo
UNIT TESTING WITH
NOSE
César Cárdenas Desales
Installing nose
• Install pip
• Install virtualenv
• Install pip on your virtual environment
• http://bit.ly/1kCeZv8
$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip install virtualenv
$ virtualenv testingenv
$ source testingenv/bin/activate
$ python get-pip.py
$ pip install nose
Step 1: Freedom, no unittest boilerplate
$ nosetests
$ nosetests basic_tests.py
$ nosetests basic_tests
Step 2: Test functions
$ nosetests
$ nosetests basic_tests
$ nosetests basic_tests:test_sum
$ nosetests basic_tests:test_failing_sum
Step 3: Test classes
$ nosetests basic_tests:TestSuite
$ nosetests basic_tests:TestSuite.test_mult
$ nosetests basic_tests:TestSuite.ignored
Step 4: Specify tests
$ nosetests --collect-only -v
$ nosetests --collect-only -v -s
$ nosetests -v -s
$ nosetests -v --nocapture
Step 5: Config files
$ nosetests -v -c config.ini
Step 6: Fixtures
=> @with_setup(setup_function, teardown_function)
$ nosetests –v
Step 7: Test generators & parallel testing
1 2 3 4 5
OK OK OK FAIL OK
$ nosetests -v
$ nosetests --processes=6
Step 8: Exceptions
$ nosetests –v
Step 9: Timeouts
$ nosetests -v basic_tests.py
$ nosetests -v --processes=6 --process-timeout=1 basic_tests2
Plugins! => --processes --no-capture –collect-only
Py.test anyone?
$ pip install pytest
$ py.test step1/basic_tests.py
$ py.test step2/basic_tests.py
$ py.test -v step4/basic_tests.py
...
Is TDD dead?
• No need to be purist and orthodox
• “I get paid for code that works, not for tests, so my philosophy is to
test as little as possible to reach a given level of confidence”
• – Kent Beck
• Test are code to maintain
• Test core algorithms, data structures, logic with Biz. Value
• Tests can become assertions
• Test give you confidence to do changes
Exercise
• Test whether the following code correctly calculates in
which quarter falls the provided datetime.date object
¿?
• ¡ !

More Related Content

PDF
pip and virtualenv
PDF
Isolated development in python
PDF
Pont entre nord et sud dans la recherche et santé publique : l'exemple du gén...
PPTX
Presentacion ocmparendo
DOC
Tema 1
PPTX
Seminario 10.1
DOC
Tema6losriosdeespana
PDF
Marca Brasil. Formação e Desenvolvimento. Nelma Soares 2008
pip and virtualenv
Isolated development in python
Pont entre nord et sud dans la recherche et santé publique : l'exemple du gén...
Presentacion ocmparendo
Tema 1
Seminario 10.1
Tema6losriosdeespana
Marca Brasil. Formação e Desenvolvimento. Nelma Soares 2008

Viewers also liked (10)

PDF
Mallas curriculares
PDF
September-2016-Tech-Front
PDF
Tema 3 procesos!
DOC
Tema 1
DOC
CV Marija Vasiljevic
PPT
La sociedad-de-la-informacion-1223721720933638-9
PDF
The making of Arla tactical decision process (S&OP)
PDF
Reglamento terceras matriculas
PDF
89001164 mantto sistemas hidraulicos
PPTX
SOAL IPS
Mallas curriculares
September-2016-Tech-Front
Tema 3 procesos!
Tema 1
CV Marija Vasiljevic
La sociedad-de-la-informacion-1223721720933638-9
The making of Arla tactical decision process (S&OP)
Reglamento terceras matriculas
89001164 mantto sistemas hidraulicos
SOAL IPS
Ad

More from Cesar Cardenas Desales (9)

PDF
PyConIT 2018 Writing and deploying serverless python applications
PDF
Migrate to Python 3 using the six library
PDF
PyConIE 2017 Writing and deploying serverless python applications
PDF
Writing and deploying serverless python applications
PDF
Scalable Web applications with Elastic Beanstalk as your PAAS: a primer
PDF
Software maintenance PyConPL 2016
PDF
Distributed Task Processing with Celery - PyZH
PDF
Software maintenance PyConUK 2016
PDF
Code Reviews in Python - PyZh
PyConIT 2018 Writing and deploying serverless python applications
Migrate to Python 3 using the six library
PyConIE 2017 Writing and deploying serverless python applications
Writing and deploying serverless python applications
Scalable Web applications with Elastic Beanstalk as your PAAS: a primer
Software maintenance PyConPL 2016
Distributed Task Processing with Celery - PyZH
Software maintenance PyConUK 2016
Code Reviews in Python - PyZh
Ad

Recently uploaded (20)

PPT
Teaching material agriculture food technology
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
A Presentation on Artificial Intelligence
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Getting Started with Data Integration: FME Form 101
PDF
cuic standard and advanced reporting.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
A Presentation on Artificial Intelligence
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Getting Started with Data Integration: FME Form 101
cuic standard and advanced reporting.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
gpt5_lecture_notes_comprehensive_20250812015547.pdf
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectral efficient network and resource selection model in 5G networks
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

Unit Testing with Nose

  • 1. UNIT TESTING WITH NOSE César Cárdenas Desales
  • 2. Installing nose • Install pip • Install virtualenv • Install pip on your virtual environment • http://bit.ly/1kCeZv8 $ wget https://bootstrap.pypa.io/get-pip.py $ python get-pip.py $ pip install virtualenv $ virtualenv testingenv $ source testingenv/bin/activate $ python get-pip.py $ pip install nose
  • 3. Step 1: Freedom, no unittest boilerplate $ nosetests $ nosetests basic_tests.py $ nosetests basic_tests
  • 4. Step 2: Test functions $ nosetests $ nosetests basic_tests $ nosetests basic_tests:test_sum $ nosetests basic_tests:test_failing_sum
  • 5. Step 3: Test classes $ nosetests basic_tests:TestSuite $ nosetests basic_tests:TestSuite.test_mult $ nosetests basic_tests:TestSuite.ignored
  • 6. Step 4: Specify tests $ nosetests --collect-only -v $ nosetests --collect-only -v -s $ nosetests -v -s $ nosetests -v --nocapture
  • 7. Step 5: Config files $ nosetests -v -c config.ini
  • 8. Step 6: Fixtures => @with_setup(setup_function, teardown_function) $ nosetests –v
  • 9. Step 7: Test generators & parallel testing 1 2 3 4 5 OK OK OK FAIL OK $ nosetests -v $ nosetests --processes=6
  • 10. Step 8: Exceptions $ nosetests –v
  • 11. Step 9: Timeouts $ nosetests -v basic_tests.py $ nosetests -v --processes=6 --process-timeout=1 basic_tests2 Plugins! => --processes --no-capture –collect-only
  • 12. Py.test anyone? $ pip install pytest $ py.test step1/basic_tests.py $ py.test step2/basic_tests.py $ py.test -v step4/basic_tests.py ...
  • 13. Is TDD dead? • No need to be purist and orthodox • “I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence” • – Kent Beck • Test are code to maintain • Test core algorithms, data structures, logic with Biz. Value • Tests can become assertions • Test give you confidence to do changes
  • 14. Exercise • Test whether the following code correctly calculates in which quarter falls the provided datetime.date object