Diferencia entre revisiones de «Usuario:Lmorillas/intropyaytozgz/nose»

De WikiEducator
Saltar a: navegación, buscar
(Página creada con '{{MiTitulo|Testing con python}}')
 
 
(2 revisiones intermedias por el mismo usuario no mostrado)
Línea 1: Línea 1:
 
{{MiTitulo|Testing con python}}
 
{{MiTitulo|Testing con python}}
 +
 +
 +
{{Conocimiento previo|
 +
Tests con python:
 +
* http://en.wikipedia.org/wiki/Portal:Software_Testing
 +
* http://docs.python.org/2/library/unittest.html
 +
* https://nose.readthedocs.org/en/latest/index.html
 +
* http://ivory.idyll.org/articles/nose-intro.html
 +
}}
 +
 +
 +
== Instalar nose ==
 +
Puedes usar pip o easy_install:
 +
easy_install nose
 +
o
 +
pip install nose
 +
 +
O instalar desde el código fuente:
 +
python setup.py install
 +
 +
Escribe los tests en el proyecto y:Now you can run tests for your project:
 +
  cd path/del/proyecto
 +
  nosetests
 +
Verás algo así:
 +
  ..................................
 +
  ----------------------------------------------------------------------
 +
  Ran 34 tests in 1.440s
 +
 
 +
  OK
 +
 +
==Escribir tests==
 +
Mira estos [http://learnpythonthehardway.org/book/ex47.html ejemplos]
 +
 +
<source lang="python">
 +
def test_a():
 +
    assert ...
 +
 +
</source>
 +
 +
Para comprobar:
 +
 +
  $ nosetests
 +
 +
== Más Ejemplos ==
 +
 +
<source lang="python">
 +
#testset.py
 +
from nose.tools import ok_, eq_, nottest
 +
 +
def test_sum():
 +
    eq_(2+2,4)
 +
 +
@nottest  # este test no empieza por test_
 +
def test_failing_sum():
 +
    ok_(2+2 == 3, "Expected failure")
 +
</source>

Última revisión de 02:26 11 dic 2012






Instalar nose

Puedes usar pip o easy_install:

easy_install nose

o

pip install nose

O instalar desde el código fuente:

python setup.py install

Escribe los tests en el proyecto y:Now you can run tests for your project:

 cd path/del/proyecto
 nosetests

Verás algo así:

 ..................................
 ----------------------------------------------------------------------
 Ran 34 tests in 1.440s
 
 OK

Escribir tests

Mira estos ejemplos

def test_a():
    assert ...

Para comprobar:

 $ nosetests

Más Ejemplos

#testset.py
from nose.tools import ok_, eq_, nottest
 
def test_sum():
    eq_(2+2,4)
 
@nottest   # este test no empieza por test_
def test_failing_sum():
    ok_(2+2 == 3, "Expected failure")