为什么 nosy (nose2) 出现错误,但 python 运行测试正常



我试图在保存文件时让测试持续运行。
我尝试使用多管闲事。

我可以使用python test_1.py运行我的测试

$ python test_1.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK

但是鼻子2给

$ nose2
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
E
======================================================================
ERROR: test_1 (nose2.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_1
Traceback (most recent call last):
File "/home/durrantm/.local/lib/python3.7/site-packages/nose2/plugins/loader/discovery.py", line 201, in _find_tests_in_file
module = util.module_from_name(module_name)
File "/home/durrantm/.local/lib/python3.7/site-packages/nose2/util.py", line 77, in module_from_name
__import__(name)
File "/home/durrantm/Dropbox/90_2019/work/code/pair_and_mob/python/for_nose_2/test_1.py", line 10, in <module>
unittest.main()
File "/usr/lib/python3.7/unittest/main.py", line 101, in __init__
self.runTests()
File "/usr/lib/python3.7/unittest/main.py", line 273, in runTests
sys.exit(not self.result.wasSuccessful())
SystemExit: False

----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
$ cat test_1.py 
import unittest
from mycode import *
class MyFirstTests(unittest.TestCase):
def test_hello(self):
self.assertEqual(hello_world(), 'hello world')
def test_goodbye(self):
self.assertEqual(goodbye_world(), 'goodbye world')
unittest.main()
$ cat mycode.py
def hello_world():
return 'hello world'
def goodbye_world():
return 'goodbye world'

我不确定,但是在测试中调用unittest.main()会导致 nose2 出现问题吗?约定是:

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

这样另一个跑步者(例如 nose2(在运行时不会调用unittest

最新更新