Python unittest-在0.000秒内额外运行了0个测试

Python unittest-在0.000秒内额外运行了0个测试,python,unit-testing,python-unittest,Python,Unit Testing,Python Unittest,以下是我的测试脚本: # tests/runner.py import unittest # import your test modules import TC110 import TC112 # initialize the test suite loader = unittest.TestLoader() suite = unittest.TestSuite() # add tests to the test suite suite.addTests(loader.loadTest

以下是我的测试脚本:

# tests/runner.py
import unittest

# import your test modules
import TC110
import TC112

# initialize the test suite
loader = unittest.TestLoader()
suite  = unittest.TestSuite()

# add tests to the test suite
suite.addTests(loader.loadTestsFromModule(TC110))
suite.addTests(loader.loadTestsFromModule(TC112))

# initialize a runner, pass it your suite and run it
runner = unittest.TextTestRunner(verbosity=3)
result = runner.run(suite)
我在同一个目录中有TC110.py和TC112.py,我正在这样运行我的测试

"python -m unittest runner"
test_ldap_login (TC110.TestTC110) ... ok
test_download_artifact (TC112.TestTC112) ... ok

----------------------------------------------------------------------
Ran 2 tests in 1.929s

OK

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
我得到这样的输出

"python -m unittest runner"
test_ldap_login (TC110.TestTC110) ... ok
test_download_artifact (TC112.TestTC112) ... ok

----------------------------------------------------------------------
Ran 2 tests in 1.929s

OK

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
为什么我要进行“Ran 0测试”,如何消除这种情况?

您要进行额外的“Ran 0测试”,其原因基本上与
print(print(“asdf”)
打印额外的
None
:您要发出两个测试命令

您的
runner.py
脚本从其他文件加载测试并运行它们。如果您只是让Python运行脚本(
Python runner.py
),就不会得到虚假的额外输出

您没有告诉Python运行脚本,而是告诉unittest模块从
runner.py
加载并运行所有测试。作为一个副作用,它运行
runner.py
的主体,运行您想要的测试
unittest
然后加载并运行
runner.py
中包含的所有0个测试,因为是您告诉它的。

您得到了一个额外的“运行0个测试”,其原因基本上与
print(print(“asdf”)
打印一个额外的
None
:您发出了两个测试命令

您的
runner.py
脚本从其他文件加载测试并运行它们。如果您只是让Python运行脚本(
Python runner.py
),就不会得到虚假的额外输出


您没有告诉Python运行脚本,而是告诉unittest模块从
runner.py
加载并运行所有测试。作为一个副作用,它运行
runner.py
的主体,运行您想要的测试
unittest
然后加载并运行
runner.py
中包含的所有0个测试,因为是您告诉它的。

如何使我的脚本与“python-m unittest”一起工作?这是出于不同的原因而提出的要求……如何使我的脚本与“python-m unittest”一起工作?这是不同原因的要求。。。