pytest框架,使用print在控制台输入

代码示例:

import pytest
@pytest.fixture(autouse=True,scope='session') #autouse=True,scope='session'
def session_scope():
print("#######################0")
yield
print("~~~~~~~~~~~~~~~~~~~~~~~1")
@pytest.mark.add
#@pytest.mark.usefixtures("session_scope")
class Test_case():
def test_one(self):
print("测试用例")

if __name__ == '__main__':
pytest.main(["-m","add"])

设置:
第一种方法:

1.打开pycharm右上角Edit Config....

2.选择python tests-----py.test

3.设置代码路径,名称随意,python版本随意,然后点击保存

4.验证成功

第二种方法:

在运行时候加个-s就行了,例如 pytest.main(["-m","add",“-s”])


原文地址:https://www.cnblogs.com/hao2018/p/10064796.html