4. Pytest基础

2024-02-08  本文已影响0人  薛东弗斯

Pycharm安装python包的四种常用方式_pycharm怎么安装各种包-CSDN博客

image.png
def test_one():
    expect = 1
    actual = 1
    assert expect == actual

def test_two():
    expect = 2
    actual = 1
    assert expect == actual
C:\Users\DELL\PycharmProjects\ApiTest\venv\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm 2021.1.3\plugins\python\helpers\pycharm\_jb_pytest_runner.py" --target test_one.py::test_two
Testing started at 11:59 ...
C:\Program Files\JetBrains\PyCharm 2021.1.3\plugins\python\helpers\pycharm\_jb_pytest_runner.py:6: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  from pkg_resources import iter_entry_points
C:\Program Files\JetBrains\PyCharm 2021.1.3\plugins\python\helpers\pycharm\_jb_pytest_runner.py:28: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Launching pytest with arguments test_one.py::test_two --no-header --no-summary -q in C:\Users\DELL\PycharmProjects\ApiTest
  if version.LooseVersion(pytest.__version__) >= version.LooseVersion("6.0"):

============================= test session starts =============================
collecting ... collected 1 item

test_one.py::test_two FAILED                                             [100%]
test_one.py:5 (test_two)
2 != 1

Expected :1
Actual   :2
<Click to see difference>

def test_two():
        expect = 2
        actual = 1
>       assert expect == actual
E       assert 2 == 1

test_one.py:9: AssertionError


============================== 1 failed in 0.15s ==============================

Process finished with exit code 1

#1. login;
#2. search
#3. order
#4. pay
def test_login():
    print('login...')

def test_search():
    print('search...')

def test_order():
    print('order...')

def test_pay():
    print('pay...')
============================= test session starts =============================
collecting ... collected 4 items

test_ordering.py::test_login PASSED                                      [ 25%]login...

test_ordering.py::test_search PASSED                                     [ 50%]search...

test_ordering.py::test_order PASSED                                      [ 75%]order...

test_ordering.py::test_pay PASSED                                        [100%]pay...


============================== 4 passed in 0.03s ==============================

Process finished with exit code 0

自定义执行顺序

import pytest
def test_login():
    print('login...')

def test_search():
    print('search...')

@pytest.mark.run(order=4)
def test_order():
    print('order...')

def test_pay():
    print('pay...')

pip install pytest-ordering

上一篇 下一篇

猜你喜欢

热点阅读