pytest框架结构运行规则及命名方式

可紊 提交于 2019-11-30 19:15:21
import pytestdef setup_module():    print('整个模块.py开始')def teardown_module():    print('整个模块的.py结束')def setup_function():    print('不在类中的函数前')def teardown_function():    print('不在类中的函数后')def test_w_one():    print('不在类中的方法1')def test_w_two():    print('不在类中的方法2')class TestClass:    def setup_class(self):        print('类前面')    def teardown_class(self):        print('类之后')    def setup_method(self):        print('方法前')    def teardown_method(self):        print('方法后')    def test_one(self):        x='this'        assert 'h' in x    def test_two(self):        x='hello'        assert 'h4'==x    def test_three(self):        a='hello'        b='hello world'        assert a in bif __name__ == '__main__':    pytest.main("-s -v","pytestDemo.py")


整个模块.py开始
不在类中的函数前
不在类中的方法1

不在类中的函数后
pytestDemo.py::test_w_one ✓ 20% ██ 不在类中的函数前
不在类中的方法2

不在类中的函数后
pytestDemo.py::test_w_two ✓ 40% ████ 类前面
方法前

方法后
pytestDemo.py::TestClass.test_one ✓ 60% ██████ 方法前


――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestClass.test_two ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

self = <pytest_2.pytestDemo.TestClass object at 0x105b0f438>

def test_two(self):
x='hello'
> assert 'h4'==x
E AssertionError: assert 'h4' == 'hello'
E - h4
E + hello

pytestDemo.py:39: AssertionError

方法后
pytestDemo.py::TestClass.test_two ⨯ 80% ████████ 方法前

方法后
类之后
整个模块的.py结束
pytestDemo.py::TestClass.test_three ✓ 100% ██████████

Results (0.14s):
4 passed
1 failed
- pytestDemo.py:37 TestClass.test_two


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!