在以前版本的Nose测试框架中,有几种方法只能指定所有测试的子集:
nosetests test.module
nosetests another.test:TestCase.test_method
nosetests a.test:TestCase
nosetests /path/to/test/file.py:test_function
Run Code Online (Sandbox Code Playgroud)
http://nose.readthedocs.org/en/latest/usage.html#selecting-tests
但是,我找不到有关Nose2中类似测试选择的任何信息.有一个提到的关于不同的测试发现文档,但似乎并没有被相关.
有没有办法在nose2或(更一般地)unittest2中选择特定的测试或测试用例?
我有一个nose.cfg文件,我正在移植到nose2.我无法在nose2文档中看到任何忽略文件或目录的方法.
在鼻子1中,这是通过这两个标志完成的:
ignore-files=settings_test*
exclude-dir=ignorethisdir
Run Code Online (Sandbox Code Playgroud)
怎么能在nose2中完成?
这是一个很简单的问题,但我无法在任何地方找到它...如何使用nose2为运行测试的输出添加颜色?例如,我希望失败显示为红色.
满足条件时,我想跳过一些测试功能,例如:
@skip_unless(condition)
def test_method(self):
...
Run Code Online (Sandbox Code Playgroud)
在这里,我希望测试方法如果condition评估为true,则报告为跳过。我用鼻子做了一些努力就可以做到这一点,但是我想看看是否可以在鼻子2中使用它。
当我运行包括调用@classmethod使用setuptools和nose2的测试时,测试套件没有完成它只是继续运行.但是我已经检查过测试确实通过并到达函数的末尾,测试套件只是没有完成运行.如果我使用decode_auth_token它删除测试工作正常.我能够将它缩小到类方法,因为我也测试了其他类方法,它们导致了同样的问题
有谁知道为什么会发生这种情况?以下是相关的代码片段,但没有发布太多的代码
我的用户模型中的代码
@classmethod
def decode_auth_token(cls, auth_token):
try:
payload = jwt.decode(auth_token, config.SECRET_KEY, algorithms=['HS256'])
# check the hash of what we expect the token to be and token we got to be the same
if bcrypt.check_password_hash(User.by_id(payload['sub']).api_token_hash, auth_token):
return payload['sub']
else:
return 'Token does not match Api Token.'
except jwt.ExpiredSignatureError:
return 'Signature expired. Please log in again.'
except jwt.InvalidTokenError:
return 'Invalid Token. Please log in again.'
Run Code Online (Sandbox Code Playgroud)
以下两个函数在调用时也会导致问题
@classmethod
def is_username_taken(cls, username):
return db.session.query(db.exists().where(User.username==username)).scalar()
@classmethod
def is_email_taken(cls, email):
return …Run Code Online (Sandbox Code Playgroud) 我想使用带覆盖插件的nose2来获取Python包的覆盖范围,但是我很难配置它以仅覆盖我正在处理的包.调用包vimhdl,我的覆盖部分unittest.cfg如下所示:
[coverage]
coverage = vimhdl
Run Code Online (Sandbox Code Playgroud)
使用nose2,结果不包括包中的所有文件(可能是因为Coverage.py warning: Module vimhdl was previously imported, but not measured.消息,但我不知道如何修复它).
此外,在打开给定文件的HTML报告时,诸如import logging和模块的doc字符串之类的语句 被标记为未涵盖.
$ nose2 --with-coverage -vvv
...
----------------------------------------------------------------------
Ran 5 tests in 0.166s
OK
Coverage.py warning: Module vimhdl was previously imported, but not measured.
---------- coverage: platform linux2, python 2.7.10-final-0 ----------
Name Stmts Miss Cover
---------------------------------------------------------
python/vimhdl/compilers/__init__.py 95 42 56%
python/vimhdl/compilers/ghdl.py 92 41 55%
python/vimhdl/config_parser.py 74 42 43%
python/vimhdl/project_builder.py 269 164 39% …Run Code Online (Sandbox Code Playgroud) 根据http://nose.readthedocs.io/en/latest的所有测试
...应考虑使用Nose2,py.test或仅使用unittest / unittest2。
但是,我似乎无法让Pycharm代替鼻子使用它。我可以配置一些设置,以便它使用鼻子2而不是鼻子进行测试吗?
nose2 ×7
python ×7
nose ×3
unit-testing ×2
coverage.py ×1
nosetests ×1
pycharm ×1
pytest ×1
python-3.x ×1
unittest2 ×1