Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52335
| Date | 2013-08-10 18:52 -0400 |
|---|---|
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: How many times does unittest run each test? |
| References | <f7b24010-f3f4-4e86-b6c4-9ddb503d0412@googlegroups.com> <roy-FE5D5B.16404310082013@news.panix.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.445.1376179409.1251.python-list@python.org> (permalink) |
On 8/10/13 4:40 PM, Roy Smith wrote: > In article <f7b24010-f3f4-4e86-b6c4-9ddb503d0412@googlegroups.com>, > Josh English <Joshua.R.English@gmail.com> wrote: > >> I am working on a library, and adding one feature broke a seemingly unrelated >> feature. As I already had Test Cases written, I decided to try to incorporate >> the logging module into my class, and turn on debugging at the logger before >> the newly-broken test. >> >> Here is an example script: > [followed by 60 lines of code] > > The first thing to do is get this down to some minimal amount of code > that demonstrates the problem. > > For example, you drag in the logging module, and do some semi-complex > configuration. Are you SURE your tests are getting run multiple times, > or maybe it's just that they're getting LOGGED multiple times. Tear out > all the logging stuff. Just use a plain print statement. Roy is right: the problem isn't the tests, it's the logging. You are calling .addHandler in the SimpleChecker.__init__, then you are constructing two SimpleCheckers, each of which adds a handler. In the LoaderTC test, you've only constructed one, adding only one handler, so the "calling q" line only appears once. Then the NameSpaceTC tests runs, constructs another SimplerChecker, which adds another handler, so now there are two. That's why the "calling a" and "calling f" lines appear twice. Move your logging configuration to a place that executes only once. Also, btw, you don't need the "del self.checker" in your tearDown methods: the test object is destroyed after each test, so any objects it holds will be released after each test with no special action needed on your part. --Ned.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How many times does unittest run each test? Josh English <Joshua.R.English@gmail.com> - 2013-08-10 13:00 -0700
Re: How many times does unittest run each test? Roy Smith <roy@panix.com> - 2013-08-10 16:40 -0400
Re: How many times does unittest run each test? Josh English <Joshua.R.English@gmail.com> - 2013-08-10 15:53 -0700
Re: How many times does unittest run each test? Roy Smith <roy@panix.com> - 2013-08-10 19:14 -0400
Re: How many times does unittest run each test? Chris Angelico <rosuav@gmail.com> - 2013-08-11 00:21 +0100
Re: How many times does unittest run each test? Josh English <Joshua.R.English@gmail.com> - 2013-08-10 17:52 -0700
Re: How many times does unittest run each test? Chris Angelico <rosuav@gmail.com> - 2013-08-11 02:10 +0100
Re: How many times does unittest run each test? Josh English <Joshua.R.English@gmail.com> - 2013-08-10 17:47 -0700
Re: How many times does unittest run each test? Josh English <joshua.r.english@gmail.com> - 2013-08-10 15:58 -0700
Re: How many times does unittest run each test? Ned Batchelder <ned@nedbatchelder.com> - 2013-08-10 18:52 -0400
csiph-web