def pytest_sessionstart(session):
    """ before session.main() is called. """
pass

def pytest_sessionfinish(session, exitstatus):
    """ whole test run finishes. """
pass
How to run a method before all tests in all classes?