473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Packages and modules

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
Jul 26 '05 #1
3 1253
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
Jul 26 '05 #2
Dan
> > 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
Jul 26 '05 #3
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?
Jul 26 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
1
by: Kwikrick | last post by:
When calling str() on a sequence or dict object, the elements of the sequence/dict will be represented as if their __repr__ method was called. Why is this? Wouldn't it be more consistent when...
3
by: Tinka | last post by:
Hi, I'm having trouble with my new directory hierarchy. My little python programme worked as long as I had all my modules in one big file. I have decided now that this was just to messy and I...
5
by: John Ladasky | last post by:
Hi folks, Running Python 2.5 on both a Windows XP laptop, and an Ubuntu Linux 7.04 desktop. I've gotten tired of maintaining multiple copies of my personal modules that I use over and over. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.