状态 | 说明 |
---|---|
| 测试通过 |
| 断言失败 |
| 用例本身代码报错 |
| 预期失败,加了 |
# -\*- coding:utf-8 -\*-
# 作者:NoamaNelson
# 日期:2022/12/27
# 文件名称:test\_case\_status.py
# 作用:用例的执行状态
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
# 断言装饰器
@pytest.mark.xfail(raises=ZeroDivisionError)
def test\_f():
1 / 0
if \_\_name\_\_ == '\_\_main\_\_':
pytest.main(["-s", "test\_case\_status.py"])
test\_case\_status.py::test\_f XFAIL [100%]
@pytest.mark.xfail(raises=ZeroDivisionError)
def test\_f():
> 1 / 0
E ZeroDivisionError: division by zero
test\_case\_status.py:14: ZeroDivisionError
============================= 1 xfailed in 0.07s ==============================
# -\*- coding:utf-8 -\*-
# 作者:NoamaNelson
# 日期:2022/12/27
# 文件名称:test\_case\_status.py
# 作用:用例的执行状态
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
# failed
@pytest.fixture()
def sum():
add = 3 + 5
assert add == 8
return add
def test\_case(sum):
assert sum == 9
if \_\_name\_\_ == '\_\_main\_\_':
pytest.main(["-s", "test\_case\_status.py"])
sum = 8
def test\_case(sum):
> assert sum == 9
E assert 8 == 9
test\_case\_status.py:24: AssertionError
=========================== short test summary info ===========================
FAILED test\_case\_status.py::test\_case - assert 8 == 9
============================== 1 failed in 0.07s ==============================
# -\*- coding:utf-8 -\*-
# 作者:NoamaNelson
# 日期:2022/12/27
# 文件名称:test\_case\_status.py
# 作用:用例的执行状态
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
@pytest.fixture()
def userinfo():
name = "zhang"
assert name == "zhang"
return name
def test\_case(userinfo):
assert userinfo == "zhang"
if \_\_name\_\_ == '\_\_main\_\_':
pytest.main(["-s", "test\_case\_status.py"])
test\_case\_status.py::test\_case PASSED [100%]
============================== 1 passed in 0.02s ==============================
@pytest.fixture()
去掉,就会error
:# -\*- coding:utf-8 -\*-
# 作者:NoamaNelson
# 日期:2022/12/27
# 文件名称:test\_case\_status.py
# 作用:用例的执行状态
# 联系:VX(NoamaNelson)
# 博客:https://blog.csdn.net/NoamaNelson
import pytest
def userinfo():
name = "zhang"
assert name == "zhang"
return name
def test\_case(userinfo):
assert userinfo == "zhang"
if \_\_name\_\_ == '\_\_main\_\_':
pytest.main(["-s", "test\_case\_status.py"])
=================================== ERRORS ====================================
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ERROR at setup of test\_case \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
file F:\pytest\_study\test\_case\test\_g\test\_case\_status.py, line 31
def test\_case(userinfo):
E fixture 'userinfo' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, cov, doctest\_namespace, metadata, monkeypatch, no\_cover, pytestconfig, record\_property, record\_testsuite\_property, record\_xml\_attribute, recwarn, tmp\_path, tmp\_path\_factory, tmpdir, tmpdir\_factory, worker\_id
> use 'pytest --fixtures [testpath]' for help on them.
F:\pytest\_study\test\_case\test\_g\test\_case\_status.py:31
=========================== short test summary info ===========================
ERROR test\_case\_status.py::test\_case
============================== 1 error in 0.03s ===============================
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。