How many times does unittest run each test?

Josh English joshua.r.english at gmail.com
Sat Aug 10 18:58:39 EDT 2013


Aha. Thanks, Ned. This is the answer I was looking for.

I use logging in the real classes, and thought that turning setting
the level to logging.DEBUG once was easier than hunting down four
score of print statements.

Josh

On Sat, Aug 10, 2013 at 3:52 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> On 8/10/13 4:40 PM, Roy Smith wrote:
>>
>> In article <f7b24010-f3f4-4e86-b6c4-9ddb503d0412 at googlegroups.com>,
>>   Josh English <Joshua.R.English at 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.



-- 
Josh English
Joshua.R.English at gmail.com
http://www.joshuarenglish.com



More information about the Python-list mailing list