Re: [Tutor] still nosing around
 snip Personally, I recommend you start with doctests rather than nose or unittest. Doctests can also be run using nose, maybe that's also an idea? Nose does doctest, unittest, and its own tests. By default, test files need to have a prefix test_. Unless you specify this either as a commanline switch or in the .cfg file, nose won't do doctests. snip ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] still nosing around
Hi, On 22 May 2013 05:26, Jim Mooney cybervigila...@gmail.com wrote: But that brings up a point. Does this mean that if I have to test a module with a lot of subroutines I have to rename every subroutine with 'test' appended? Some quick comments for what it's worth: (One of) the points about nose is to make lessen the overhead needed to write tests. With unittest, you have to create a subclass of unittest.Testcase in order to identify and package tests for the test framework, and manually organise them into suites. This is fine, but slightly burdensome if all you want is to write a function or functions that tests another function or functions (maybe working still in just one single file at that point, as it were, on a single function or so.) Nose allows you to do this, e.g. just start writing tests with as little friction/resistance as possible. But there's a question: How is the test runner now supposed to know whether an arbitrary function in a module is in fact a test? With unittest, the test framework knows (get it) by the fact that tests are descended from a common base class. But with an arbitrary function, how should the test framework know? So to answer your question: In short, yes, you have to let nose know whether a given piece of code is a test. Either include the word test in the function name either prefixed or postfixed as _test as you asked Or you can do it like unittest requires, e.g. create a test class descended from unittest.Testcase, in which case your method names then don't matter IIRC. You may have read this already, but the relevant documentation page: https://nose.readthedocs.org/en/latest/writing_tests.html Aside, doctest answers/approaches this same question by reading IIRC docstring entries for classes, methods or modules (?) and assumes that text that looks like python interpreter styled input/output sequences defines test input/output sequences. Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] still nosing around
On 22 May 2013 05:26, Jim Mooney cybervigila...@gmail.com wrote: But that brings up a point. Does this mean that if I have to test a module with a lot of subroutines I have to rename every subroutine with 'test' appended? No, you don't rename the existing functions. But the testing functions need to be identifiable, in one of several ways. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] still nosing around
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 -- Jim Mooney When I got to high school I realized my name would always present problems. --Dick Hertz ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] still nosing around
On 22/05/2013 01: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 Do you ever bother to investigate anything before posing a question? I know nothing about nose, but when I see output telling me that precisely nothing has been run, I'd hazard a guess that stupid_error has to be called test_stupid_error or similar. I'll leave you to check the nose docs to confirm whether or not my guess is correct. -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] still nosing around
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
Re: [Tutor] still nosing around
On 22/05/13 10:50, Mark Lawrence wrote: Do you ever bother to investigate anything before posing a question? That's rather harsh. The OP is doing a fine job at investigating new tools, and he's far more adventurous than I was at his level of expertise. (Or now, for that matter...) I think we can forgive him the occasional whoops moment. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor