Problems using nose in a virtualenv
我无法在virtualenv项目中使用"鼻子"(noestests)-它似乎找不到在virtualenv环境中安装的软件包。
奇怪的是我可以设定
1 | test_suite = 'nose.collector' |
在setup.py中运行测试,就像
1 | python setup.py test |
但是当直接进行鼻子测试时,会出现各种各样的导入错误。
我已经尝试过在整个系统范围内安装鼻子和一个virtualenv鼻子包,但没有运气。
有什么想法吗?
谢谢!!
您需要在虚拟环境中安装一份鼻子的副本。为了强制将鼻子安装到virtualenv中,即使它已经安装在全局站点程序包中,请使用
1 | (env1)$ pip install nose -I |
从那时起,您可以照常运行
您可以运行
在相同的情况下,我需要重新加载
1 2 | deactivate env/bin/activate |
我遇到了类似的问题。以下变通办法有所帮助:
1 | python `which nosetests` |
(而不只是
这对我有用:
1 2 3 4 5 6 7 | $ virtualenv --no-site-packages env1 $ cd env1 $ source bin/activate # makes"env1" environment active, # you will notice that the command prompt # now has the environment name in it. (env1)$ easy_install nose # install nose package into"env1" |
我创建了一个非常基本的包
如果您查看
1 2 3 4 | slither/setup.py slither/slither/__init__.py slither/slither/impl.py # has some very silly code to be tested slither/slither/tests.py # has test-cases |
我可以使用
1 2 3 4 5 6 7 8 | (env1)$ pushd src/slither (env1)$ python setup.py test # ... output elided ... test_ctor (slither.tests.SnakeTests) ... ok test_division_by_zero (slither.tests.SnakeTests) ... ok Ran 2 tests in 0.009s OK (env1)$ popd |
或者,我可以使用
1 2 3 4 5 6 | (env1)$ pushd src (env1)$ nosetests slither/ .. Ran 2 tests in 0.007s OK (env1)$ popd |
另请注意,
如果所有其他方法都失败,请尝试在您的venv中安装鼻子,和/或运行
您可能在
1 | export PATH=/path/to/current/virtualenv/bin:$PATH |
也许这是最近的更改,但是对我来说,当我通过pip安装耐压测试时,在