繁体   English   中英

如何在鼻子2中运行单个测试用例

[英]How to run a single test case in nose2

我想在如何在Nose2中运行特定测试之后 ,使用nose2 运行 unittest.TestCase子类中包含的单个测试,但是它似乎对我不起作用。 我正在使用以下示例脚本,我将其命名为mickey_mouse_test.py

import unittest

class TestMickeyMouse(unittest.TestCase):
    def test_1plus1is2(self):
        self.assertTrue(1+1 == 2)

    def test_to_uppercase(self):
        self.assertEqual("hello".upper(), "HELLO")

if __name__ == "__main__":
    unittest.main()

如果我在同一目录中运行nose2 mickey_mouse_test ,它将运行模块中的所有测试:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

但是,如果我尝试像这样仅运行test_to_uppercase ,那么我会得到一个错误:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
AttributeError: module 'mickey_mouse_test' has no attribute 'test_to_uppercase'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

如果我使用-s选项,我仍然会收到错误消息,尽管有所不同:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 -s mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
OSError: /home/kurt/Documents/Scratch/mickey_mouse_test.test_to_uppercase is not a directory

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

我还尝试阅读http://nose2.readthedocs.io/en/latest/usage.html中的“指定要运行的测试”部分,其中声明“ Python对象部分”应为“虚线”名称'。 我不明白为什么在这种情况下mickey_mouse_test.test_to_uppercase不是“点缀名称”。 任何想法为什么这不起作用?

这是一种只使用test_to_uppercase而不使用nose2 (在通过命令行从unittest.TestCase运行单个测试之后 ):

kurt@kurt-ThinkPad:~/Documents/Scratch$ python mickey_mouse_test.py TestMickeyMouse.test_to_uppercase
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM