@songying
2018-08-19T07:31:14.000000Z
字数 456
阅读 1151
pytest
pip install -U pytest
pytest 会运行当前目录及其子目录下所有格式为test_*.py或*_test.py的文件。
使用raises helper来判断是否抛出了异常
import pytestdef f():raise SystemExit(1)def test_mytest():with pytest.raises(SystemExit):f()
pytest -q test_sysexit.py
# content of test_class.pyclass TestClass(object):def test_one(self):x = "this"assert 'h' in xdef test_two(self):x = "hello"assert hasattr(x, 'check')pytest -q test_class.py
