setting package path
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
In numpytest.py, set_package_path is provided for handling path changes while doing unit tests. It reads def set_package_path(level=1): """ Prepend package directory to sys.path. set_package_path should be called from a test_file.py that satisfies the following tree structure: <somepath>/<somedir>/test_file.py Then the first existing path name from the following list <somepath>/build/lib.<platform>-<version> <somepath>/.. is prepended to sys.path. ... However, the line that supposedly calculates "somepath/.." is d = os.path.dirname(os.path.dirname(os.path.abspath(testfile))) which calculates "somepath". Which is wrong: the docstring, the code or my interpretation? Stéfan
![](https://secure.gravatar.com/avatar/9b85a909fbfc71a3ea3275c7872e714d.jpg?s=120&d=mm&r=g)
On Wed, 1 Mar 2006, Stefan van der Walt wrote:
You have to read also following code: d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3])) if not os.path.isdir(d1): d1 = os.path.dirname(d) # <- here we get "somepath/.." sys.path.insert(0,d1) Pearu
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
On Tue, Feb 28, 2006 at 11:34:43PM -0600, Pearu Peterson wrote:
Pearu, Thanks for pointing this out. I was trying to figure out why my module's tests didn't run when I did, for example: $ python test_geom.py But now I realise it is because typical package layout is "somepath/some_dir/tests/test_file.py", not "somepath/some_dir/test_file.py". For example, we have "numpy/core/tests/test_umath.py". As a temporary workaround, set_local_path("../../..") works for me. Regards Stéfan
![](https://secure.gravatar.com/avatar/9b85a909fbfc71a3ea3275c7872e714d.jpg?s=120&d=mm&r=g)
On Wed, 1 Mar 2006, Stefan van der Walt wrote:
You have to read also following code: d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3])) if not os.path.isdir(d1): d1 = os.path.dirname(d) # <- here we get "somepath/.." sys.path.insert(0,d1) Pearu
![](https://secure.gravatar.com/avatar/af6c39d6943bd4b0e1fde23161e7bb8c.jpg?s=120&d=mm&r=g)
On Tue, Feb 28, 2006 at 11:34:43PM -0600, Pearu Peterson wrote:
Pearu, Thanks for pointing this out. I was trying to figure out why my module's tests didn't run when I did, for example: $ python test_geom.py But now I realise it is because typical package layout is "somepath/some_dir/tests/test_file.py", not "somepath/some_dir/test_file.py". For example, we have "numpy/core/tests/test_umath.py". As a temporary workaround, set_local_path("../../..") works for me. Regards Stéfan
participants (2)
-
Pearu Peterson
-
Stefan van der Walt