python - 在 Nose 中运行与单元测试子类无关的单个测试函数

标签 python nose

nose 发现以 test_ 开头的测试,以及 unittest.TestCase 的子类。

如果希望运行单个 TestCase 测试,例如:

# file tests.py
class T(unittest.TestCase):
    def test_something():
        1/0

这可以在命令行上完成:

nosetests tests:T.test_something

我有时更喜欢编写一个简单的函数并跳过所有unittest样板:

def test_something_else():
    assert False

在这种情况下,当运行我的所有测试时,测试仍将由 nose 运行。但是我如何使用 (Unix) 命令行告诉 nose 仅运行该测试?

最佳答案

那就是:

nosetests tests:test_something_else

另一个技巧是使用属性

from nose.plugins.attrib import attr

@attr('now')
def test_something_else():
    pass

要运行用该属性标记的所有测试,请执行:

nosetests -a now

相反,避免运行这些测试:

nosetests -a !now

关于python - 在 Nose 中运行与单元测试子类无关的单个测试函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15282503/

相关文章:

python - 是否可以在 noses setup.cfg 中设置环境变量

python - 避免每次运行脚本时加载数据库

Tornado 中页面上的 Python web 开发动态字段 id

python - 如何在 Python 3 中打印出编号列表

python - 原始输入处的 Nose 测试卡住

python - 覆盖范围是跳过返回语句

python - 打印函数如何在 if 语句条件下工作?

Python:有效计算字典列表中键的唯一值的数量

python - 如何从python中的文件(json或yaml)动态创建参数化测试

python doctest默认命名空间