Python test Tool--nose

Source: Internet
Author: User
Tags naming convention

1, Nose features:

A) Autodiscover test case (contains the [Tt]est file and the function that contains test in the package)

b) A file that starts with test

c) A function or method that begins with test

d) classes that begin with test

Nose automatically collects unit tests that automatically identify test cases in source code files, directories, or packages, and any regular expressions that match: (?: ^| [b_.-]) [Tt]est class, function, file or directory, and TestCase subclasses are recognized and executed, matching successful packages, any Python source files will be treated as test cases.

2. Nose setup and teardown:

A) setup, teardown, in the Packages (package), which is placed in the __init__.py file, runs only once during the entire test run

b) module level: Setup_module, teardown_module-> run only once during the entire test run

C) class level: Setup_class, teardown_class-> each test method executes when it is called

3 ,nose related execution command:

1. Nosetests–h View all nose related commands

2. Nosetests–s Execute and capture output

3. Nosetests–with-xunit Output XML Results report

4, Nosetests-v: View Nose's operation information and debugging information

5. Nosetests-w directory: Specify a directory to run the test

4, Nose test Code execution method:

1.CD + file address to execute (e.g. C:\Users\zhangjx\test_main\Test1\test), nosetests

2. Implementation of test cases using coding

Create main.py (the name is optional), the content is as follows:

Execution can:

Or:

Execution results can be seen to return TRUE or flase

Or:

3. Run the entire package directly: Nosetests-v test_case

4. Run a module: Nosetests–v test_case.test_case_0002

5. Run a use case: Nosetests-v test_case.test_case_0002:test_lean_4

6. Run different use cases in different modes:

Nosetests-v--tests=test_case.test_case_0002:test_lean_4,test_case.test_case_0001:test_lean_2

5, the use of tool Nose.tools:

1) introduced in the test script: from nose.tools import nottest,istest;

2) Non-test method: Method name plus modifier @nottest;

3) specified as the test method: The method name is added to the decorator @istest (the method name does not need to conform to the naming convention);

4) View the list of use cases to be performed: Nosetests--collect-only–v

Python test Tool--nose

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.