[英]Python: How to run tests made with unittest
This is the structure of my project, and I would like to run the test that I have made from the command line.这是我的项目的结构,我想运行我从命令行所做的测试。
I am using the following command:我正在使用以下命令:
python test_hotel.py
However I am getting the following error但是我收到以下错误
ImportError: No module named 'hotel'
What can I do to solve this problem, and is there a way to execute the whole tests in a project from the command line.我能做些什么来解决这个问题,有没有办法从命令行在项目中执行整个测试。
Thanks in advance.提前致谢。
For running unittest from commandline, you should use this command:要从命令行运行 unittest,您应该使用以下命令:
python -m unittest tests.test_hotel
You need to make sure that you have followed the rules in writing unittests ( https://docs.python.org/2/library/unittest.html )您需要确保遵循编写单元测试的规则( https://docs.python.org/2/library/unittest.html )
As @shahram kalantari said to run a tests the command line is:正如@shahram kalantari 所说,要运行测试,命令行是:
python -m unittest tests.test_hotel
If one wants to run the whole tests the command line is:如果想运行整个测试,命令行是:
python -m unittest discover tests
If you want more information about what tests were run the -v
flag should be included:如果您想了解有关运行哪些测试的更多信息,应包含
-v
标志:
python -m unittest discover tests -v
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.