pytest 一.安装和使用入门
pytest 一.安装和使用入门
# -*- coding: utf-8 -*-
# @Time : 2018/7/5 23:57
# @Author : onesilent
# @File : FirstTest.py
# @Project : PythonTestDemo
# content of test_sample.py
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
# -*- coding: utf-8 -*-
# @Time : 2018/7/5 23:57
# @Author : onesilent
# @File : FirstTest.py
# @Project : PythonTestDemo
# content of test_sample.py
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
# -*- coding: utf-8 -*-
# @Time : 2018/7/10 23:29
# @Author : onesilent
# @File : test_sysexit.py
# @Project : PythonTestDemo
# content of test_sysexit.py
import pytest
def f():
raise SystemExit(1)
def test_mytest():
with pytest.raises(SystemExit):
f()
# -*- coding: utf-8 -*-
# @Time : 2018/7/10 23:29
# @Author : onesilent
# @File : test_sysexit.py
# @Project : PythonTestDemo
# content of test_sysexit.py
import pytest
def f():
raise SystemExit(1)
def test_mytest():
with pytest.raises(SystemExit):
f()
# -*- coding: utf-8 -*-
# @Time : 2018/7/11 0:00
# @Author : onesilent
# @File : test_class.py
# @Project : PythonTestDemo
# content of test_class.py
class TestClass(object):
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
# -*- coding: utf-8 -*-
# @Time : 2018/7/11 0:00
# @Author : onesilent
# @File : test_class.py
# @Project : PythonTestDemo
# content of test_class.py
class TestClass(object):
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
通过请求唯一临时目录完成功能测试
# -*- coding: utf-8 -*-
# @Time : 2018/7/11 23:57
# @Author : onesilent
# @File : test_tmpdir.py
# @Project : PythonTestDemo
# content of test_tmpdir.py
def test_needsfiles(tmpdir):
print (tmpdir)
assert 0
# -*- coding: utf-8 -*-
# @Time : 2018/7/11 23:57
# @Author : onesilent
# @File : test_tmpdir.py
# @Project : PythonTestDemo
# content of test_tmpdir.py
def test_needsfiles(tmpdir):
print (tmpdir)
assert 0
pytest --fixtures #此命令显示内置命令和custom fixtures 请注意,除非添加-v选项,否则此命令将省略带有前导_的 fixtures。
pytest --fixtures #此命令显示内置命令和custom fixtures 请注意,除非添加-v选项,否则此命令将省略带有前导_的 fixtures。
<wiz_tmp_tag id=”wiz-table-range-border” contenteditable=”false” style=”display: none;”>