开发者

How do i add a python package path during runtime

Here is a scenario, i hope you can help me with.

I have python unit tests in /home/k/PR-TEST/Pr/test

kahmed@qatools:~/PR-TEST/Pr-test$ ls
_apache.py        archive  clienttest  decorators.py   fakeTecoreClient.py  fixtures.pyc     psqlharness.py  servertest   testhelp.pyc  testutils.pyc
apache_server.py  cache    commontest  decorators.pyc  fixtures.py          mysqlharness.py  runtests.sh     testhelp.py  testutils.py

and have the package that i am actually running tests against @ /home/k/PR/Pr named (directory named) pref

kahmed@qatools:~/PR/Pr$ pwd
/home/kahmed/PR/Pr
kahmed@qatools:~/PR/Pr$ ls
bin  conf  images  init.d  iped  logrotate.d  NEWS  pref  rpa  sbin  scripts  src  test  VERSION

Now, i cd to ~/PR-TEST/Pr-test, and run:

nosetests -s --with-coverage --cover-package /home/k/PR/Pr/pref  `find . -name "*test.py"`

but i get erros that it cannot find the packages in pref

Any idea how to resolve this ?

I have to make sure that the python environment knows开发者_JS百科 about the package pr


If you cannot (or do not want to) modify PYTHONPATH before you start the program, you can modify sys.path during runtime to achive similar functionality.
But in this case you will need to wrap the call to nosetests script. Also please check that you do not have case-sensitivity issue with your package being called Pr vs pr.


You should add paths to your packages to PYTHONPATH environment variable


You should put your application package in a directory "foo/app" and the tests in another sub directory called "foo/tests". Then run your tests from the foo directory so that they can import the app directly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜