My project struct like
.
├── test_dir_1
│ ├── conftest.py
│ ├── test_case_1.py
│ └── test_case_3.py
└── test_dir_2
├── conftest.py
└── test_case_2.py
conftest:
import pytest
from loguru import logger
@pytest.fixture(scope="package", autouse=True)
def package_hook(request):
logger.info("suite setup hook")
yield
logger.info("suite teardown hook")
This structure execution log like
... INFO | test_dir_1.conftest:package_hook:7 - suite setup hook
PASSED
... INFO | test_dir_1.conftest:package_hook:10 - suite teardown hook
... INFO | test_dir_2.conftest:package_hook:7 - suite setup hook
PASSED
... INFO | test_dir_2.conftest:package_hook:10 - suite teardown hook
Now I hope to omit the conftest files in the directory and still retain functionality;
I am trying to create a conftest file in the root path of the project, like this:
.
├── conftest.py
├── test_dir_1
│ ├── __init__.py
│ ├── test_case_1.py
│ └── test_case_3.py
└── test_dir_2
├── __init__.py
└── test_case_2.py
conftest:
import pytest
from loguru import logger
@pytest.fixture(scope="package", autouse=True)
def package_hook(request):
logger.info("suite setup hook")
yield
logger.info("suite teardown hook")
But the execution results and expectations are not satisfactory,
This structure execution log like
... | INFO | conftest:package_hook:7 - suite setup hook
PASSED
PASSED
... | INFO | conftest:package_hook:10 - suite teardown hook
I hope to execute each directory once instead of only executing once in total.
How should I implement it, perhaps by using other hooks to dynamically add conftest to the test directory?
aka00 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.