简体   繁体   中英

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:

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 )

As @shahram kalantari said to run a tests the command line is:

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:

python -m unittest discover tests -v

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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