I could not find a solid example on doing so. Here is the situation.
I have several fixtures written in a Python file called my_fixtures.py
& a conftest.py
containing configuration for the fixtures like below:
import pytest
from glob import glob
def refactor(string: str) -> str:
return string.replace("/", ".").replace("\\", ".").replace(".py", "")
pytest_plugins = [
refactor(fixture) for fixture in glob("tests/fixtures/*.py") if "__" not in fixture
]
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
meanwhile in my_fixtures.py
, here are the codes:
@pytest.fixture
def transport(resource) -> Transport:
...
return t
@pytest.fixture
def microservice(transport, request, resource) -> Microservice:
...
yield m
m.stop_logging() # must stop logging handler
Both files above are located in Project A with the folder structure below:
project-a
┣ src
┃ ┗ joebus
┃ ┃ ┣ topics.py
┃ ┃ ┗ __init__.py
┗ tests
┃ ┣ fixtures
┃ ┃ ┗ my_fixtures.py
┃ ┣ conftest.py
┃ ┗ test_simple.py
Let say I have another project called project-b
, and it needs to use the fixtures from project-a's my_fixtures.py
& the test cases in project-b
needs to use everything in project-a's conftest.py
, how this can be done via pip install project-a
?
P/S: I have studied the only article discussing it and other question here, but I would like to see an example.
Thanks