[mod_python] Testing for mod_python

Deron Meranda deron.meranda at gmail.com
Fri Dec 1 14:18:16 EST 2006

On 12/1/06, Eric Brunson <brunson at brunson.com> wrote:
> I've converted my code over to use the 3.3 PythonOption mod_python.path,
> but our regression tests run outside of mod_python, so I need to
> conditionally mess with the sys.path.
> I've come up with this:
> try:
>     # throws an exception when trying to load '_apache' outside mod_python
>     from mod_python import apache
> except ImportError:
>     import sys
>     sys.path.append( './lib' )
> and it works fine, but is there a better way to do this check?

Trapping ImportErrors is actually a pretty reasonable way to handle this.
I'm not aware of any future plans that would ever allow the import to
succeed outside of an Apache environment, so I think this is a safe
thing to do.
Deron Meranda

More information about the Mod_python mailing list