Rya*_*yan 46 python nose virtualenv nosetests
我无法在virtualenv项目中使用nose(nosetests) - 它似乎无法找到virtualenv环境中安装的软件包.
奇怪的是我可以设置
test_suite = 'nose.collector'
Run Code Online (Sandbox Code Playgroud)
在setup.py中运行测试就好了
python setup.py test
Run Code Online (Sandbox Code Playgroud)
但是当直接运行nosetests时,会出现各种导入错误.
我尝试了系统范围的鼻子安装和virtualenv鼻子包,没有运气.
有什么想法吗?
谢谢!!
edw*_*ard 60
您需要在虚拟环境中安装一个nose副本.为了强制将nose安装到virtualenv中,即使它已经安装在全局站点包中,也要pip install
使用-I
标志运行:
(env1)$ pip install nose -I
Run Code Online (Sandbox Code Playgroud)
从那时起你可以nosetests
像往常一样运行.
Joh*_*kin 44
你能跑myenv/bin/python /usr/bin/nosetests
吗?这应该使用虚拟环境的库集运行Nose.
And*_*nca 10
在相同的情况下,我需要重新加载virtualenv
路径才能正确更新:
deactivate
env/bin/activate
Run Code Online (Sandbox Code Playgroud)
我遇到了类似的问题.以下解决方法有助于:
python `which nosetests`
Run Code Online (Sandbox Code Playgroud)
(而不仅仅是nosestests
)
这对我有用:
$ 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"
Run Code Online (Sandbox Code Playgroud)
我创建了一个非常基本的包slither
,它具有setup.py
与test_suite
上面提到的相同的属性.然后我把包源放在下面env1/src
.
如果你向里看env1/src
,你会看到:
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
Run Code Online (Sandbox Code Playgroud)
我可以使用test
子命令运行测试:
(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
Run Code Online (Sandbox Code Playgroud)
或者,我可以运行相同的测试nosetests
:
(env1)$ pushd src
(env1)$ nosetests slither/
..
Ran 2 tests in 0.007s
OK
(env1)$ popd
Run Code Online (Sandbox Code Playgroud)
另请注意,nosetests
可执行文件可能很挑剔.--exe
如果您希望它在可执行的python模块中发现测试,则可以传递.
归档时间: |
|
查看次数: |
13083 次 |
最近记录: |