• 场景: 只执行符合要求的某一部分用例, 通过类与方法的命名实
现. 通常编写测试方法时
• 解决: 直接输入文件名, 类名
pytest test_class_01.py
• pytest -v -s test_class_01.py
• pytest -v test_class_01.py::TestClass
• pytest -v test_class_01.py::TestClass::test_one
- import pytest
- def 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 b
- if __name__ == '__main__':
- pytest.main(["-v","/Users/chengyanan/Desktop/Venv_data/pytest_allure/pytest_2/pytestDemo.py"])
- pytest -s -v pytestDemo.py::TestClass::test_one
来源: http://www.bubuko.com/infodetail-3231620.html