How to execute set of code before or after each test case using PyTest.

 You can use PyTest Fixture for this. In below example, code before yield will execute before every test case and code after yield will execute after every test case.

@pytest.fixture()
def fix_method()
    global driver
    path = ""
    driver = Chrome(executable_path = path)
    driver.get("");
    yield
    driver.close()