简体   繁体   English

“python3 -m test”和“python3 -m unittest”之间的区别

[英]Difference between "python3 -m test" and "python3 -m unittest"

I found out that I can discover and run unit tests under my directory tree by doing this:我发现我可以通过这样做在我的目录树下发现和运行单元测试:

python3 -m test

The above works, but the documented method to discover and run all tests finds hundreds more, including a new one that was not found by the previous method:上面的 方法是有效的,但是发现和运行所有测试的 记录方法发现了数百个,包括一个以前方法没有发现的新方法:

python3 -m unittest

What exactly is -m test and why can't I find documentation on it after a quick search, except the following page which seems to be about CPython? -m test究竟是什么,为什么我在快速搜索后找不到有关它的文档,除了以下似乎是关于 CPython 的页面?

https://devguide.python.org/runtests/ https://devguide.python.org/runtests/

The test package is intended to test the Python API itself. test包旨在测试 Python API 本身。 According to the documentation:根据文档:

Note: The test package is meant for internal use by Python only.注意: test包仅供 Python 内部使用。 It is documented for the benefit of the core developers of Python.为了 Python 的核心开发人员的利益,它被记录下来。 Any use of this package outside of Python's standard library is discouraged as code mentioned here can change or be removed without notice between releases of Python.不鼓励在 Python 标准库之外使用此包,因为此处提到的代码可能会在 Python 版本之间更改或删除,恕不另行通知。

The link to this documentation appears in the TOC under Development Tools .此文档的链接出现在开发工具的目录中 While it is not entirely surprising that the python3 -m test command discovers and runs tests, it is not really designed to discover and run the tests that you write for your own code.虽然python3 -m test命令发现并运行测试并不完全令人惊讶,但它并不是真正设计为发现和运行您为自己的代码编写的测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM