Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Packages and modules

Reply
Thread Tools

Packages and modules

 
 
Dan Richter
Guest
Posts: n/a
 
      07-26-2005
I'm trying to create a package+module structure, specifically a "test"
package with all the unit tests. I'd like to have a package (directory)
"test" that has various test modules, and I'd also like "test" itself to
be a module that runs all the tests. Is this not possible?

I created a directory called "test" with an __init__.py file that
defines a variable __all__. That works, but no executable code in
__init__.py is executed, even though "import test" seems to succeed. I
have confirmed that it's not a naming conflict (i.e., there's not some
other Python module also named "test").

--
I had picked out the theme of the baby's room and done other
things. I decided to let Jon have this.
- Jamie Cusack (of the Netherlands), whose husband Jon
finally talked her into letting him name their son Jon 2.0


 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      07-26-2005
Dan Richter wrote:
> I'm trying to create a package+module structure, specifically a "test"
> package with all the unit tests. I'd like to have a package (directory)
> "test" that has various test modules, and I'd also like "test" itself to
> be a module that runs all the tests. Is this not possible?
>
> I created a directory called "test" with an __init__.py file that
> defines a variable __all__. That works, but no executable code in
> __init__.py is executed, even though "import test" seems to succeed. I
> have confirmed that it's not a naming conflict (i.e., there's not some
> other Python module also named "test").


Are you certain? The way to check is with "test.__file__" after
importing test. There _is_ a standard library package called test, and
when I import test here and do this test I get:

>>> test.__file__

'c:\\python24\\lib\\test\\__init__.pyc'

-Peter
 
Reply With Quote
 
 
 
 
Dan
Guest
Posts: n/a
 
      07-26-2005
> > no executable code in
> > __init__.py is executed, even though "import test" seems to succeed.


I've discovered that "import test" *does* cause executable code in the
package to be executed. However, I can't execute it on the command line
using "python test". Is there a way to do this?

> There _is_ a standard library package called test


Oh, you're right. But I've renamed the module to XYZ and I still have
the problem.

--
They had a big meeting, drank some beer and had some pizza and
decided 'A' would be 65.
- Jim Greenly, professor at Georgia Institute of Technology


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      07-26-2005
Dan wrote:
>>>no executable code in
>>>__init__.py is executed, even though "import test" seems to succeed.

>
> I've discovered that "import test" *does* cause executable code in the
> package to be executed. However, I can't execute it on the command line
> using "python test". Is there a way to do this?


Using the latest version of Python, "python -m test" should do it,
though I don't know if that works for packages, or just modules. Hang
on... appears to work only for modules.

Okay, this should be universal, if slightly more awkward:

python -c "import xyz"

The problem with this approach is that it won't execute the "if __name__
== '__main__':" code at the end, so if you want to execute a particular
function directly, just add the call manually:

python -c "import xyz; xyz.main()"

>>There _is_ a standard library package called test

> Oh, you're right. But I've renamed the module to XYZ and I still have
> the problem.


Which problem?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python Packages : A loomingproblem? packages might no longer work? (well not on your platform or python version anyway) David Lyon Python 19 04-23-2009 11:10 PM
Advice on converting hashed packages to pseudo-hashed packages Ian Perl Misc 3 02-12-2005 12:17 AM
Do the javax.imageio packages replace packages in com.sun.image? Paul Smith Java 0 11-18-2003 02:58 PM



Advertisments