如何 运行 mypy 覆盖我的测试代码?
How to run mypy over my test code?
我有一个项目,其中只有验收测试代码是 Python,我想确保我已经正确输入注释。目前测试 运行 如下:
python -m unittest discover test
有没有什么方法可以将 mypy
集成到该命令中而无需太多更改?我不想 运行 测试两次。我是否必须覆盖 unittest.TestLoader
才能执行此操作?
或者,mypy
支持 运行ning 模块 -m
/--module
,但 mypy --module=unittest discover test
失败
mypy: error: May only specify one of: module, package, files, or command.
有没有办法将模块参数传递给mypy
?
mypy 根本没有 运行 Python 代码。它是严格的静态分析程序。所以在这种情况下没有 "run[ning] the tests twice" 这样的东西。也就是说,您不必等待测试 运行 从 mypy 获得结果。只需 运行 mypy 测试包或模块,就像使用 non-test 代码一样(对于简单情况,mypy test_foo.py
,对于更复杂的情况,请参见 the mypy documentation)。
我有一个项目,其中只有验收测试代码是 Python,我想确保我已经正确输入注释。目前测试 运行 如下:
python -m unittest discover test
有没有什么方法可以将 mypy
集成到该命令中而无需太多更改?我不想 运行 测试两次。我是否必须覆盖 unittest.TestLoader
才能执行此操作?
或者,mypy
支持 运行ning 模块 -m
/--module
,但 mypy --module=unittest discover test
失败
mypy: error: May only specify one of: module, package, files, or command.
有没有办法将模块参数传递给mypy
?
mypy 根本没有 运行 Python 代码。它是严格的静态分析程序。所以在这种情况下没有 "run[ning] the tests twice" 这样的东西。也就是说,您不必等待测试 运行 从 mypy 获得结果。只需 运行 mypy 测试包或模块,就像使用 non-test 代码一样(对于简单情况,mypy test_foo.py
,对于更复杂的情况,请参见 the mypy documentation)。