@songying
2018-08-19T15:31:14.000000Z
字数 456
阅读 944
pytest
pip install -U pytest
pytest 会运行当前目录及其子目录下所有格式为test_*.py
或*_test.py
的文件。
使用raises helper来判断是否抛出了异常
import pytest
def f():
raise SystemExit(1)
def test_mytest():
with pytest.raises(SystemExit):
f()
pytest -q test_sysexit.py
# 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')
pytest -q test_class.py