On 22/05/13 10:25, Jim Mooney wrote:
Okay, why is nose saying this run is OK when I purposely screwed it up?

import nose

def stand_and_deliver():
     return 52

def stupid_error():
     '''This is my stupid error'''
     assert stand_and_deliver() == 17

if __name__ == '__main__':
     nose.runmodule()

nose result:

Ran 0 tests in 0.000s

OK


"Ran 0 tests" -- does that give you a clue? Nose is not running any tests. I 
have never used nose, so I don't know how you write tests for it, but whatever you are 
supposed to do, you haven't done it.

Let's see what Google has to say... this looks promising.

http://nose.readthedocs.org/en/latest/testing.html


As far as I can tell from about 30 seconds reading that page, your tests have 
to inherit from unittest.TestCase, or they have to be in a function, class or 
module called TestMatch.

(There must be something useful about nose, but frankly I don't see the benefit 
of running it instead of just using unittest directly.)


Personally, I recommend you start with doctests rather than nose or unittest. 
Change your module to this:

=== cut ===

def stand_and_deliver():
    """Always returns 52.

    >>> stand_and_deliver()
    52

    """
    return 52


def stupid_error():
    """This is my stupid error.

    >>> stupid_error()
    17

    """
    return stand_and_deliver() + 1000


if __name__ == '__main__':
    import doctest
    failed, run = doctest.testmod()
    if failed == 0:
        print("Successfully ran %d doc tests." % run)


=== cut ===



Run that file, and you should get 1 failed test out of 2, and a description of 
how it failed.





--
Steven
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to