setting package path
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
On Wed, 1 Mar 2006, Stefan van der Walt wrote:
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?
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
On Tue, Feb 28, 2006 at 11:34:43PM -0600, Pearu Peterson wrote:
which calculates "somepath". Which is wrong: the docstring, the code or my interpretation?
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, 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