具有此类 DSL 的 nose2 找不到测试

nose2 with such DSL does not find tests

这可能真的很愚蠢,但我无法让它工作... 我想在 nose2 中使用 such DLS,在 Linux 中使用 python 2.7。 我正在尝试文档 http://nose2.readthedocs.org/en/latest/such_dsl.html 中示例的开头(请参阅下面的代码),但它不会 运行 测试,无论我如何从命令行启动它。

我的文件名为 test_something.py,它是目录中唯一的文件。 我已经尝试使用 >> nose2>> nose2 --plugin nose2.plugins.layers 从命令行 运行ning,但我总是得到 Ran 0 tests in 0.000s。使用 >> nose2 --plugin layers 我得到 ImportError: No module named layers.

我应该如何从命令行 运行 此测试?? 谢谢!

代码如下:

import unittest
from nose2.tools import such

with such.A("system with complex setup") as it:
    @it.has_setup
    def setup():
        print "Setup"
        it.things = [1]

    @it.has_teardown
    def teardown():
        print "Teardown"
        it.things = []

    @it.should("do something")
    def test():
        print "Test"
        assert it.things
        it.assertEqual(len(it.things), 1)

卫生部! 我忘了在文件末尾添加it.createTests(globals())