pytest命令及控制台输出参数解释

pytest控制台输出参数解释

案例:
test_pytest_duan.py

import pytest
import allure


def test_01():
    pytest.assume (1 == 1)


def test_02():
    pytest.assume (1 == 2)


def test_03():
    pytest.assume (False)


@pytest.mark.skip(reason='跳过这个功能')
def test_04():
    pytest.assume (2 == 3)


@pytest.mark.xfail
def test_05():
    pytest.assume (3 == 4)


@pytest.mark.xfail
def test_06():
    pytest.assume (4 == 4)


if __name__ == "__main__":
    pytest.main()

运行结果:

Testing started at 15:06 ...
D:\Python37\python.exe "D:\PyCharm 2019.1.3\helpers\pycharm\_jb_pytest_runner.py" --path E:/源码/testframework/excise/pytestDemo/test_pytest_duan.py
Launching pytest with arguments E:/源码/testframework/excise/pytestDemo/test_pytest_duan.py in E:\源码\testframework\excise\pytestDemo
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.2.5, py-1.10.0, pluggy-0.12.0
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pypom-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0collected 6 items

test_pytest_duan.py .F
test_pytest_duan.py:8 (test_02)
tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>	pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption
F
test_pytest_duan.py:12 (test_03)
tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>	pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption
s
Skipped: 跳过这个功能
x
tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:24: AssumptionFailure
E               >>	pytest.assume (3 == 4)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption
X                                               [100%]

================================== FAILURES ===================================
___________________________________ test_02 ___________________________________

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>	pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption
___________________________________ test_03 ___________________________________

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>	pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption
=========================== short test summary info ===========================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption: 
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption: 
======== 2 failed, 1 passed, 1 skipped, 1 xfailed, 1 xpassed in 0.32s =========

Process finished with exit code 0

Assertion failed 断言失败

Assertion failed 断言失败

报告汇总显示

符号 描述
. 用例执行通过
F Failure 用例执行不通过
E error 测试异常
s skip 跳过
x xfail 预期失败并确实失败
X xpass 预期失败但实际通过,不符合预期
======== 2 failed, 1 passed, 1 skipped, 1 xfailed, 1 xpassed in 0.32s =========
符号 描述
2 failed 2次失败
1 passed 1通过
1 skipped 1跳过
1 xfailed 1 x失败
1 xpassed 1 X通过
in 0.32s 在0.32秒内

常用pytest命令选项

-q 获取测试方法名称列表

执行:

$ pytest --collect-only test_pytest_duan.py
============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-6.2.5, py-1.10.0, pluggy-0.12.0
sensitiveurl: .*
rootdir: E:\Դ▒▒\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pypom-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collected 6 items

<Package pytestDemo>
  <Module test_pytest_duan.py>
    <Function test_01>
    <Function test_02>
    <Function test_03>
    <Function test_04>
    <Function test_05>
    <Function test_06>

========================= 6 tests collected in 0.09s ==========================
$ pytest -q --collect-only test_pytest_duan.py
test_pytest_duan.py::test_01
test_pytest_duan.py::test_02
test_pytest_duan.py::test_03
test_pytest_duan.py::test_04
test_pytest_duan.py::test_05
test_pytest_duan.py::test_06

6 tests collected in 0.01s

$ pytest -q --collect-only test_pytest_duan.py | head -n -2
test_pytest_duan.py::test_01
test_pytest_duan.py::test_02
test_pytest_duan.py::test_03
test_pytest_duan.py::test_04
test_pytest_duan.py::test_05
test_pytest_duan.py::test_06

打印每个模块的测试数量

$ pytest -qq --collect-only test_pytest_duan.py
test_pytest_duan.py: 6

-x 如果某个测试函数被断言失败,或者触发了外部异常,则该测试用例的运行就会停止,遇到失败便全局停止

E:\源码\pytestDemo>pytest -v -m test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
cachedir: .pytest_cache
metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'pytest': '6.2.5', 'py': '1.10.0', 'pluggy': '0.12.0'}, 'Plugins': {'allure-pyt
est': '2.9.43', 'assume': '2.4.3', 'base-url': '1.4.2', 'datadir': '1.3.1', 'datafiles': '2.0', 'forked': '1.3.0', 'html': '3.1.1', 'metadata': '1.11.0', 'ordering
': '0.6', 'play': '1.4.0', 'pypom-navigation': '2.0.3', 'rerunfailures': '10.2', 'selenium': '2.0.1', 'splinter': '3.3.1', 'sugar': '0.9.4', 'variables': '1.9.0',
'xdist': '2.4.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_112', 'Base URL': '', 'Driver': None, 'Capabilities': {}}
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
======================================================================== warnings summary ========================================================================
test_mark_zi_09.py:4
  E:\源码\testframework\excise\pytestDemo\test_mark_zi_09.py:4: PytestUnknownMarkWarning: Unknown pytest.mark.webtest - is this a typo?  You can register custom ma
rks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.webtest

test_mark_zi_09.py:9
  E:\源码\testframework\excise\pytestDemo\test_mark_zi_09.py:9: PytestUnknownMarkWarning: Unknown pytest.mark.apptest - is this a typo?  You can register custom ma
rks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.apptest

test_mark_zi_09.py:14
  E:\源码\testframework\excise\pytestDemo\test_mark_zi_09.py:14: PytestUnknownMarkWarning: Unknown pytest.mark.android - is this a typo?  You can register custom m
arks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.android

test_mark_zi_09.py:19
  E:\源码\testframework\excise\pytestDemo\test_mark_zi_09.py:19: PytestUnknownMarkWarning: Unknown pytest.mark.ios - is this a typo?  You can register custom marks
 to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.ios

test_ordering_09.py:8
  E:\源码\testframework\excise\pytestDemo\test_ordering_09.py:8: PytestUnknownMarkWarning: Unknown pytest.mark.last - is this a typo?  You can register custom mark
s to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.last

-- Docs: https://docs.pytest.org/en/stable/warnings.html

Results (1.34s):
      77 deselected

E:\源码\testframework\excise\pytestDemo>pytest -x test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
 test_pytest_duan.py ✓                                                                                                                               17% █▋
  

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_02 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>      pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               33% ███▍
    
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Results (0.43s):
       1 passed
       1 failed
         - test_pytest_duan.py:9 test_02

–maxfail=num,遇到失败几次再停止

从共6条用例,执行了3条,当错误数量达到2的时候便停止了执行

E:\源码\pytestDemo>pytest --maxfail=2 test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
 test_pytest_duan.py ✓                                                                                                                               17% █▋
  

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_02 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>      pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               33% ███▍
    

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_03 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>      pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               50% █████
     
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 2 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Results (0.41s):
       1 passed
       2 failed
         - test_pytest_duan.py:9 test_02
         - test_pytest_duan.py:13 test_03

- -tb=

命令 描述
pytest --showlocals 在回溯中显示局部变量
pytest -l 显示局部变量(快捷方式)
pytest --tb=auto (默认)第一个和最后一个条目的长回溯,其他条目的短回溯
pytest --tb=long 详细的信息追踪格式
pytest --tb=short 短回溯格式
pytest --tb=line 每次失败只有一行
pytest --tb=native Python标准库格式
pytest --tb=no 没有任何追溯
pytest --full-trace 导致在错误上打印非常长的跟踪(比 --tb=long 还长)

-v (- -verbose)

增加冗长

-q (- -quiet)

减少冗长

- -lf (- -last-failed)

仅重新运行上次运行时失败的测试(如果没有失败,则全部重新运行)

- -ff (- -failed-first)

运行所有测试,但首先运行最后的失败。这可能会重新安排测试,从而导致重复安装/拆卸夹具

E:\源码\testframework\excise\pytestDemo>pytest --ff --tb=no test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... run-last-failure: rerun previous 2 failures first


 test_pytest_duan.py ⨯                                                                                                                               17% █▋
  

 test_pytest_duan.py ⨯                                                                                                                               33% ███▍
 test_pytest_duan.py ⨯✓                                                                                                                              50% █████
 test_pytest_duan.py ⨯✓s                                                                                                                             67% █████
 test_pytest_duan.py ⨯✓sx                                                                                                                            83% █████
 test_pytest_duan.py ⨯✓sxX                                                                                                                          100% █████
█████
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption:

Results (0.24s):
       1 passed
       1 xpassed
       2 failed
         - test_pytest_duan.py:9 test_02
         - test_pytest_duan.py:13 test_03
       1 xfailed
       1 skipped


-s与–capture=method

-s等同于–capture=no

-l (–showlocals)

显示回溯中的本地变量(默认禁用)

- -durations=N

显示N个最慢的设置/测试持续时间(所有设置/测试持续时间均为N=0)

E:\源码\testframework\excise\pytestDemo>pytest --durations=2 test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
 test_pytest_duan.py ✓                                                                                                                               17% █▋
  

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_02 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>      pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               33% ███▍
    

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_03 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>      pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               50% █████
 test_pytest_duan.py ⨯s                                                                                                                              67% █████
 test_pytest_duan.py ⨯sx                                                                                                                             83% █████
 test_pytest_duan.py ⨯sxX                                                                                                                           100% █████
█████
====================================================================== slowest 2 durations =======================================================================
0.07s call     test_pytest_duan.py::test_01
0.01s call     test_pytest_duan.py::test_06
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption:

Results (0.49s):
       1 passed
       1 xpassed
       2 failed
         - test_pytest_duan.py:9 test_02
         - test_pytest_duan.py:13 test_03
       1 xfailed
       1 skipped


-vv

将方法名打印出来

E:\源码\pytestDemo>pytest --durations=2 test_pytest_duan.py -vv
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
cachedir: .pytest_cache
metadata: {'Python': '3.7.3', 'Platform': 'Windows-10-10.0.18362-SP0', 'Packages': {'pytest': '6.2.5', 'py': '1.10.0', 'pluggy': '0.12.0'}, 'Plugins': {'allure-pyt
est': '2.9.43', 'assume': '2.4.3', 'base-url': '1.4.2', 'datadir': '1.3.1', 'datafiles': '2.0', 'forked': '1.3.0', 'html': '3.1.1', 'metadata': '1.11.0', 'ordering
': '0.6', 'play': '1.4.0', 'pypom-navigation': '2.0.3', 'rerunfailures': '10.2', 'selenium': '2.0.1', 'splinter': '3.3.1', 'sugar': '0.9.4', 'variables': '1.9.0',
'xdist': '2.4.0'}, 'JAVA_HOME': 'C:\\Program Files\\Java\\jdk1.8.0_112', 'Base URL': '', 'Driver': None, 'Capabilities': {}}
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
 test_pytest_duan.py::test_01 ✓                                                                                                                      17% █▋
  

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_02 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>      pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py::test_02 ⨯                                                                                                                      33% ███▍
    

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_03 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>      pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py::test_03 ⨯                                                                                                                      50% █████
     
 test_pytest_duan.py::test_04 s                                                                                                                      67% █████
█▋   
 test_pytest_duan.py::test_05 x                                                                                                                      83% █████
███▍ 
 test_pytest_duan.py::test_06 X                                                                                                                     100% █████
█████
====================================================================== slowest 2 durations =======================================================================
0.07s call     test_pytest_duan.py::test_01
0.01s call     test_pytest_duan.py::test_02
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption:

Results (0.48s):
       1 passed
       1 xpassed
       2 failed
         - test_pytest_duan.py:9 test_02
         - test_pytest_duan.py:13 test_03
       1 xfailed
       1 skipped

-r

生成一个简短的概述报告,同时配合-r还可以使用

符号 描述
f failed
E error
s skipped
x xfailed
X xpassed
p passed
P passed with output
a all except pP
A all

例如只想看失败的和跳过的测试,可以这样执行

E:\源码\pytestDemo>pytest -rfs test_pytest_duan.py
Test session starts (platform: win32, Python 3.7.3, pytest 6.2.5, pytest-sugar 0.9.4)
sensitiveurl: .*
rootdir: E:\源码\testframework\excise\pytestDemo
plugins: allure-pytest-2.9.43, assume-2.4.3, base-url-1.4.2, datadir-1.3.1, datafiles-2.0, forked-1.3.0, html-3.1.1, metadata-1.11.0, ordering-0.6, play-1.4.0, pyp
om-navigation-2.0.3, rerunfailures-10.2, selenium-2.0.1, splinter-3.3.1, sugar-0.9.4, variables-1.9.0, xdist-2.4.0
collecting ... 
 test_pytest_duan.py ✓                                                                                                                               17% █▋
  

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_02 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:10: AssumptionFailure
E               >>      pytest.assume (1 == 2)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               33% ███▍
    

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― test_03 ―
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

tp = <class 'pytest_assume.plugin.FailedAssumption'>, value = None, tb = None

    def reraise(tp, value, tb=None):
        try:
            if value is None:
                value = tp()
            if value.__traceback__ is not tb:
>               raise value.with_traceback(tb)
E               pytest_assume.plugin.FailedAssumption: 
E               1 Failed Assumptions:
E               
E               test_pytest_duan.py:14: AssumptionFailure
E               >>      pytest.assume (False)
E               AssertionError: assert False

D:\Python37\lib\site-packages\six.py:692: FailedAssumption

 test_pytest_duan.py ⨯                                                                                                                               50% █████
 test_pytest_duan.py ⨯s                                                                                                                              67% █████
 test_pytest_duan.py ⨯sx                                                                                                                             83% █████
 test_pytest_duan.py ⨯sxX                                                                                                                           100% █████
█████
==================================================================== short test summary info =====================================================================
FAILED test_pytest_duan.py::test_02 - pytest_assume.plugin.FailedAssumption:
FAILED test_pytest_duan.py::test_03 - pytest_assume.plugin.FailedAssumption:
SKIPPED [1] test_pytest_duan.py:17: 跳过这个功能

Results (0.50s):
       1 passed
       1 xpassed
       2 failed
         - test_pytest_duan.py:9 test_02
         - test_pytest_duan.py:13 test_03
       1 xfailed
       1 skipped


你可能感兴趣的:(python,pytest)