Teamcity 消息 unittest 在 Python 2 中看不到测试

Teamcity messages unittest doesnt see tests in Python 2

我有一个结构如下的项目

test_scripts.py 由单个 unittest.TestCase class 组成,并以以下代码结束。

if __name__ == '__main__':
    try:
        from teamcity import is_running_under_teamcity
        from teamcity.unittestpy import TeamcityTestRunner
        if is_running_under_teamcity():
            runner = TeamcityTestRunner()
        else:
            runner = unittest.TextTestRunner()
    except ModuleNotFoundError:
        runner = unittest.TextTestRunner()
    unittest.main(testRunner=runner)

所以当我尝试 运行 它与 python3 python3 -m teamcity.unittestpy 我得到

... some tests output
##teamcity[testFinished timestamp='2019-11-14T14:08:24.591' duration='0' flowId='tests.test_scripts.Test.test_sub' name='tests.test_scripts.Test.test_sub']


Ran 7 tests in 0.004s

OK

但是当我对 Python 2

做同样的事情时
python -m teamcity.unittestpy
##teamcity[testCount timestamp='2019-11-14T14:09:16.392' count='0']


Ran 0 tests in 0.000s

OK

我 100% 确定 teamcity-messages 安装在 python 解释器上。 为什么它看不到测试?

在 Python 2 中,它仅适用于 python -m teamcity.unittestpy discover 调用。 此调用也适用于 Python 3.