[issue8454] unittest Module Problem with different Kinds of Invocation

Perbandt report at bugs.python.org
Mon Apr 19 13:27:11 CEST 2010

New submission from Perbandt <adalbert.perbandt at infineon.com>:

I just figured out a problem with the Python module 'unittest.py',
version 1.63.

The function '__init__' behaves a bit strange in certain circumstances.
It is called either directly from the command line or it is called when
unit tests are to be executeded from a script.
The latter form is used by the pyunit Ant task. It generates such a
python script an passes it into a python process. Example:

import unittest
s = open('PyUnit-report.log', 'w')
The paroblem with this way of activating the unittest module is that
in the function parseArgs (lines 775 to 796) the first element from
argv is skipped:
778: options, args = getopt.getopt(argv[1:], 'hHvq',
779                                ['help','verbose','quiet'])
This way the first test module from the list of test modules passed in
by pyunit gets lost.

After analyzing your code I think it would be better to do the
skipping of the first element from argv directly in the __init__
method of the class 'TestProgram' at lines 760, 761. The code there
should look as follows:
760     if argv is None:
761         argv = sys.argv[1:]
This code would skip the first element from the argv array only when
the __init__ method would be called indirectly from the command line.

components: Extension Modules
messages: 103576
nosy: AP
severity: normal
status: open
title: unittest Module Problem with different Kinds of Invocation
type: behavior
versions: Python 2.5

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list