Unit testing framework PyTest

1. Install third-party packages

pip install pytest
Copy the code

2. The parameterized

Unittest uses DDT parameterization, pyTest can use built-in DDT

# single parameterization
@pytest.mark.parametrize('password', ("123"."$@ # 4222"))
# multiparameterize
@pytest.mark.parametrize('username,password', [("1287328"."1231"), ("123123"."234234")])

Copy the code

3. Skip a use case

@pytest.mark.skip
Copy the code

4. Scope

Scope is the scope that defines the use case domain:

Function: The default scope, called by every function or method, if left blank

Class: called once per class

Module: called once for each.py file, which can have multiple functions and classes

Session: multiple files called at once, across files, as in.py files, each of which is the module scope:

session > module > class > function

Report generation

1. Install third-party packages

#python3 install allure pack not the same as 2
pip3 install allure-pytest
# python2 is an error when running under 3
pip install pytest-allure-adaptor
Copy the code

2. Download allure

Allure Windows download address: dl.bintray.com/qameta/gene…

Configure environment variables

4. Run the command in the Terminal project directory

pytest -v test_login.py  -s --alluredir report
Copy the code

5. Convert the JSON file to HTML

# CMD go to the report directory
allure generate --clean report
Copy the code

Jenkins integration

1. Install allure on Jenkins.

Step1: go to the Jenkins plugin website and download the latest version of allure:

Mirrors.jenkins-ci.org/plugins/all…

Step2: Open Jenkins and choose System Management > Plug-in Management >Advanced > Upload Plugin

To upload the. Phi format plug-in, click “Upload” operation.

Configure the Allure command line in the Jenkins Global Tool. Do the following configuration (Allure and JDK) in System Administration – > Global Tools Configuration – >, complete the configuration and save: Click Global to go to Global Tools Configuration

System Management – Plug-in management – Install the Email Extension plug-in