En Fri, 22 Aug 2008 10:48:50 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]>
escribió:
On 18 ago, 08:28, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
A package is a library, meant to be imported by some other code. Your
main script (or the testing code) is a program, it uses (i.e. imports)
the library.
You are right that a module is a library and its main use is to be
imported from another module or program. But is a common practice in
Python to introduce testing code as part as the module itself. Even
there is an option “-m” to do that.
So (in my humbled opinion), that is one error Python must fix.
A *module* or a *package*? The OP asked how to test a package, and a
package is clearly a library. In the final application, it will be
imported. So the test code should mimic the same environment, and import
the package.
The easiest way to import a package is to run a script from its container
directory: the current directory is already in sys.path so the package
directory is found directly without messing with sys.path, PYTHONPATH
variable and such. This is my suggested approach, but there are many other
alternatives. Anyway, the idea is to import the package to test it.
If you don't import the package and just run some script from inside it,
how would Python know that it belongs to a package? Looking for a
__init__.py in the same directory? what if __init__.py contains code? when
should it be executed?
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list