Pytest init setup for few modules

If you mean only once in each run of the test suit, then setup and teardown are what you are looking for.

def setup_module(module):
    print ("This will at start of module")

def teardown_module(module):
    print ("This will run at end of module")

Similarly you can have setup_function and teardown_function which will run at start and end of each test function repetitively. You can also add setup and teardown member function in test classes to run at start and end of the test class run.


You can use autouse fixtures:

# content of test/conftest.py 

import pytest
@pytest.fixture(scope="session", autouse=True)
def execute_before_any_test():
    # your setup code goes here, executed ahead of first test

See pytest fixture docs for more info.