Skip to content
Advertisement

Import conftest.py from peer package

Currently, I have two packages as part of my test repository with the following folder structure:

Package_A
|--__init__.py
|--conftest.py
|--test_A.py

Package_B
|--__init__.py
|--test_B.py

As part of this, my requirement is to call fixtures defined in Package_A/conftest.py from Package_B/test_B.py. I understand that this could be done easily if Package B was within Package A. However, because of certain requirements that is not possible. Is there a way I could just import all fixtures defined in conftest of Package A into Package B instead of duplicating them into the package. Thanks.

Advertisement

Answer

After searching a little further, was able to solve this through the following re-structuring and using pytest plugins instead:

Package_A
|--__init__.py
|--fixtures.py - Define the fixtures to be shared across packages
|--conftest.py (Import fixtures.py by using 'pytest_plugins')
|--test_A.py

Package_B
|--__init__.py
|--conftest.py (Import fixtures.py from Package A by using 'pytest_plugins')
|--test_B.py
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement