test_04login.py
import requests
import pytest
@pytest.mark.smoke
def test_login01():
url = "http://192.168.3.4:8888/api/login"
# 账号密码正确
payload = '{"username":"admin","password":"admin","recaptcha":""}'
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=payload, headers=headers)
assert response.status_code == 200
@pytest.mark.get
@pytest.mark.smoke
def test_login02():
url = "http://192.168.3.4:8888/api/login"
# 密码错误
payload = '{"username":"admin","password":"123456","recaptcha":""}'
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=payload, headers=headers)
assert response.status_code == 403
D:\pytest\ch1>pytest -v -m 'smoke' test_04login.py
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-4.0.2, py-1.7.0, pluggy-0.8.0 -- C:\ProgramData\Anaconda3\python.exe
cachedir: .pytest_cache
rootdir: D:\pytest\ch1, inifile:
plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.2.0, arraydiff-0.3
collected 2 items
test_04login.py::test_login01 PASSED [ 50%]
test_04login.py::test_login02 PASSED [100%]
============================== warnings summary ===============================
D:\pytest\ch1>pytest -v -m "smoke and get" test_04login.py
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-4.0.2, py-1.7.0, pluggy-0.8.0 -- C:\ProgramData\Anaconda3\python.exe
cachedir: .pytest_cache
rootdir: D:\pytest\ch1, inifile:
plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.2.0, arraydiff-0.3
collected 2 items / 1 deselected
test_04login.py::test_login02 PASSED [100%]
============================== warnings summary ===============================
D:\pytest\ch1>pytest -v -m "smoke or get" test_04login.py
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-4.0.2, py-1.7.0, pluggy-0.8.0 -- C:\ProgramData\Anaconda3\python.exe
cachedir: .pytest_cache
rootdir: D:\pytest\ch1, inifile:
plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.2.0, arraydiff-0.3
collected 2 items
test_04login.py::test_login01 PASSED [ 50%]
test_04login.py::test_login02 PASSED [100%]
============================== warnings summary ===============================
D:\pytest\ch1>pytest -v -m "not get" test_04login.py
============================= test session starts =============================
platform win32 -- Python 3.7.1, pytest-4.0.2, py-1.7.0, pluggy-0.8.0 -- C:\ProgramData\Anaconda3\python.exe
cachedir: .pytest_cache
rootdir: D:\pytest\ch1, inifile:
plugins: remotedata-0.3.1, openfiles-0.3.1, doctestplus-0.2.0, arraydiff-0.3
collected 2 items / 1 deselected
test_04login.py::test_login01 PASSED [100%]
============================== warnings summary ===============================
网友评论