nosetests执行不以tes开头的方法

2024-06-01 09:36:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个nosetest类来测试一个特定的方法-test\u method()

当我运行这个模块的时候,我注意到nosetests运行了其他的方法,就像我们一样-create\u test\u private\u方法。你知道吗

我以为鼻测试只会测试从测试开始的方法。你知道吗

import unittest

class test(unittest.TestCase):

    def create_test_private_method(self):
        self.assertEqual(1,1)


    def test_method(self):
        self.assertEqual(2,2)

输出:

create_test_private_method (nosetest.test) ... ok
test_method (nosetest.test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.009s

OK

Tags: 模块方法testimportselfdefcreateok
1条回答
网友
1楼 · 发布于 2024-06-01 09:36:36

nosetests docs

Any python source file, directory or package that matches the testMatch regular expression (by default: (?:^|[b_.-])[Tt]est) will be collected as a test (or source for collection of tests).

为了避免这种行为,你可以

相关问题 更多 >