Advantages of Hiring UIUX Design Service Providers for Your Business
Python-nose: A unittest-based testing framework for Python that makes writing and running tests easier
1. Python-nose: A unittest-based testing framework
for Python that makes writing and running tests
easier
Timo Stollenwerk
April 27th, 2009
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
2. Introduction
Usually: Write unit tests with boilerplate code
Automated test discovery and running process for unittest
Intended to mimic the behavior of py.test
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
3. Installation
$ e a s y _ i n s t a l l nose
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
4. Egg Installation
setup.py
...
setup (
...
t e s t _ s u i t e =' n o s e . c o l l e c t o r ' ,
t e s t _ r e q u i r e s =[ ' nose ' ] ,
i n s t a l l _ r e q u i r e s =[
...
' nose ' ,
],
...
)
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
5. Basic Usage
nosetests [options] [(optional) test les or directories]
Options
Test selection (path, package, function, etc.)
Run only tests with certain attributes
PDB
Plugins
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
6. Basic Usage: Conguration
/.noserc
[ nosetests ]
v e r b o s i t y =3
with − d o c t e s t =1
d o c t e s t − e x t e n s i o n =. t x t
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
7. Writing Unit Tests
Simplest possible failing test:
def test ( ) :
assert False
And the simplest passing test:
def test ( ) :
pass
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
8. Example Unit Tests
from l x m l i m p o r t o b j e c t i f y
c l a s s TestTransform ( ) :
d e f setUp ( s e l f ) :
from html2docbook i m p o r t Html2DocBook
h2d = Html2DocBook ( )
s e l f . h2d = h2d
def test_paragraphs ( s e l f ) :
html = 'plorem /ppipsum /p'
e x p e c t = ' s e c t i o n paralorem /paraparai
xml = s e l f . h2d . t r a n s f o r m ( html )
a s s e r t xml == e x p e c t
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
9. Automate your Unit tests with Nose
nosy.py
Every time you change any .py le, it runs tests
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
10. Automate your Unit tests with Nose and Eclipse
Go to the project properties
Dene a new programbuilder
Set the location to the nosetest script
Set the working directory to the project location
${workspace_loc:/html2docbook}
Optional: append any command line options you want
Go to the build optionstag and tick the launch in
backgroundänd during auto builds.
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
11. Conclusion
Nose makes it easier to write and run useful tests.
Useful tests make it easier to write less code and better code.
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho
12. Futher Information
Nose: http://code.google.com/p/python-nose/
nosy.py: http://jeffwinkler.net/2006/04/27/
keeping-your-nose-green/
Automated python testing with nose and eclipse:
http://www.machine-envy.com/blog/2006/07/29/
automated-python-testing-with-nose-and-eclipse/
Pycon 2008 Talk: Testing for the lazy coder
http://us.pycon.org/common/2008/talkdata/
PyCon2008/079/nose_pycon08.pdf
Timo Stollenwerk Python-nose: A unittest-based testing framework for Pytho