Skip to content Skip to sidebar Skip to footer

Why Can't Nosetests Find One The Elements In Sys.path?

I have a series of unit tests that I'm running with nose. For some of my tests, I'd like to remove a module's path from the sys.path so there is no conflict with what I am testing.

Solution 1:

Didn't you mean this?

sys.path.remove('/path/to/remove/from/sys/path')

If nose can't find it in sys.path then it wasn't there... nose does lots of diddling with sys.path on its own. Why not print sys.path and see what it actually is when run under nose

Solution 2:

Create a script, get_mod_py_path.py, to set the PYTHONPATH. In this case, it is dropping the conflicted path.

import os
import sys

# Remove the global Python modules from the PYTHONPATH.
path = os.environ['PYTHONPATH'].split(os.pathsep)
ifos.environ['GLOB_PY_MODULES'] inpath: 
    path.remove(os.environ['GLOB_PY_MODULES'])

# Construct the new pathandprint it. 
path = ':'.join(path)
printpath

Then use it in a bash that calls nosetests.

PYTHONPATH=`python get_mod_py_path.py`   
nosetests --verbosity=1 --with-gae --where="../tests/unit" --gae-application="../app"

Post a Comment for "Why Can't Nosetests Find One The Elements In Sys.path?"