import pytest
@pytest.fixture(scope='session', autouse=True) def connect_db(): print("Connect Database in .......") yield print("Close Database out .......")
def test1(): print("test1")
def test2(): print("test")
============================= test session starts ============================= platform win32 -- Python 3.6.8, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- D:\Coding\Python3.6\python.exe cachedir: .pytest_cache rootdir: C:\Users\libuliduobuqiuqiu\Desktop\GitProjects\PythonDemo\pytest plugins: Faker-8.11.0 collecting ... collected 2 items
test_example.py::test1 Connect Database in ....... PASSED [ 50%]test1
test_example.py::test2 PASSED [100%]test Close Database out .......