在 virtualenv 中使用鼻子的问题
我无法在 virtualenv 项目中使用鼻子(nosetests) - 它似乎无法找到 virtualenv 环境中安装的软件包。
奇怪的是,我可以
test_suite = 'nose.collector'
在 setup.py 中设置并运行测试,
python setup.py test
但当直接运行鼻子测试时,会出现各种导入错误。
我已经尝试过在系统范围内安装鼻子和 virtualenv 鼻子包,但没有成功。
有什么想法吗?
谢谢!!
I am unable to use nose (nosetests) in a virtualenv project - it can't seem to find the packages installed in the virtualenv environment.
The odd thing is that i can set
test_suite = 'nose.collector'
in setup.py and run the tests just fine as
python setup.py test
but when running nosetests straight, there are all sorts of import errors.
I've tried it with both a system-wide installation of nose and a virtualenv nose package and no luck.
Any thoughts?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您需要在虚拟环境中安装鼻子的副本。 为了强制将nose安装到virtualenv中,即使它已经安装在全局站点包中,也要使用
-I
标志运行pip install
:从那时起您可以照常运行
nosetests
。You need to have a copy of nose installed in the virtual environment. In order to force installation of nose into the virtualenv, even though it is already installed in the global site-packages, run
pip install
with the-I
flag:From then on you can just run
nosetests
as usual.您可以运行 myenv/bin/python /usr/bin/nosetests 吗? 这应该使用虚拟环境的库集运行 Nose。
Are you able to run
myenv/bin/python /usr/bin/nosetests
? That should run Nose using the virtual environment's library set.在同样的情况下,我需要重新加载 virtualenv 才能正确更新路径:
In the same situation I needed to reload the
virtualenv
for the path to be correctly updated:我遇到了类似的问题。 以下解决方法有所帮助:(
而不仅仅是
nosestests
)I got a similar problem. The following workaround helped:
(instead of just
nosestests
)这对我有用:
我创建了一个非常基本的包
slither
,在其setup.py
中,具有与您上面提到的相同的test_suite
属性。 然后我将包源放在env1/src
下。如果您查看
env1/src
内部,您会看到:我可以使用
test
子命令运行测试:或者,我可以使用
nosetests< 运行相同的测试/code>:
另请注意,
nosetests
对可执行文件可能很挑剔。 如果您希望它发现可执行的 python 模块中的测试,您可以传递--exe
。Here's what works for me:
I created a really basic package
slither
that had, in itssetup.py
, sametest_suite
attribute as you mentioned above. Then I placed the package source underenv1/src
.If you looked inside
env1/src
, you'd see:I can run the tests using
test
subcommand:Or, I can run the same tests with
nosetests
:Also note that
nosetests
can be picky about executables. You can pass--exe
if you want it to discover tests in python modules that are executable.如果所有其他方法都失败,请尝试在您的 venv 中安装鼻子,和/或运行
nosetests-2.7
。 我相信如果你的 venv python 是 2.7,@andrea-zonca 的答案也有同样的效果If all else fails, try installing nose in your venv, and/or run
nosetests-2.7
. I believe @andrea-zonca's answer has the same effect if your venv python is 2.7也许这是最近的变化,但对我来说,当我通过 pip 安装osetests 时,
.virtualenvs//bin
中安装了一个osetests 可执行文件,它(毫不奇怪)可以正确运行虚拟环境。Perhaps this is a recent change, but for me, when I installed nosetests through pip, there was a nosetests executable installed in
.virtualenvs/<env>/bin
, which (unsurprisingly) operates correctly with the virtualenv.您可能在
PATH
中的其他位置安装了nosetests
,其优先级高于安装在 virtualenv 中的优先级。 为当前 virtualenv 中安装的nose
模块和关联的nosetests
脚本提供最高优先级的快速方法是编辑您的PATH
:You might have a
nosetests
that is installed somewhere else in yourPATH
with higher priority than the one installed in your virtualenv. A quick way to give thenose
module and associatednosetests
script installed in your current virtualenv top priority is to edit yourPATH
:聚会迟到了。
无论如何,如果你在 2021 年看到这种情况......
对我来说,围绕nose、nose-cov 和 pinocchio 的这些问题已通过将我的虚拟环境更新到至少 Python 3.8.2 来解决。
Late to the party.
Regardless, if you see this in the year 2021...
These issues, for me, surrounding nose, nose-cov and pinocchio were resolved by updating my Virtual Envs to at least Python 3.8.2..