Pycharm python and unittest two kinds of posture silly divide not clear "reprint"

Source: Internet
Author: User

Objective

Often someone in the group feedback, clearly code the same ah, why other people can report, I do not report; Why do people run the result is not the same as mine ah ...

This problem first check the code, OK is the same, that is the wrong running posture, once imported unittest module, Pycharm will automatically identify to unittest posture to run.

First, UnitTest run a single use case

1. The following code, if I only want to run one of them, such as Test1, how to run it?

2. If you want to run a use case, mouse over the corresponding area, right-click to run a single use case directly

3. Note The red box, which shows the run ' UnitTest test01 ', which means it is clear that UnitTest only runs test01

If you want to run Test2, the mouse is placed in the Test2 area right button, it will be displayed: Run ' unittest test02 '

Second, UnitTest run the entire script use case

1. If you want to execute all the use cases on the current script, simply place the mouse over the IF __name__ = = "__main__": The following or below the sentence.

2. It shows that run UnitTest in Test1 is running the entire script

Third, Python direct operation mode

1. The above method can only execute the contents of the unit test framework, is not the output of the test report, if you want to output the test report, can be run in a non-unittest mode, that is, directly run with Python

2. In the top right corner, tap open: Edit configurations

2. Expand Python and Python tests these two options, you will find the script name just run under the Python Tests this option, that is, pycharm this tool automatically defaults to UnitTest posture run.

3. The solution, just remove the line from here, select this script, point to the upper left corner of the minus: a

4. After removing all, click Apply, then click OK to save

5. Go back to the scripting interface and right-click to run the test report.

(Knocking on the blackboard!!!) The mouse must be placed in the if the right side of the line to see the normal display run ' test1 ')

Pycharm python and unittest two kinds of posture silly divide not clear "reprint"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.