代码示例:

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....

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

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

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

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

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

4.验证成功

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

第二种方法:

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


 
                    
            
                

相关文章:

  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2021-06-29
  • 2021-06-30
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
猜你喜欢
  • 2022-01-08
  • 2022-02-10
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案