Open Vic152 opened 5 years ago
In another words hooks are triggered globally even if they are implemented in two different conftest.py
Did you find any solution? I have this problem too(but in before scenario hook).
here is my structure:
.
├── t1
│ ├── conftest.py
│ ├── t1.feature
│ └── test_pt1.py
└── t2
├── conftest.py
├── t2.feature
└── test_pt2.py
Content of the conftest file:
def pytest_bdd_before_scenario(request, feature, scenario):
print("-----------t1 conftest-----------")
# for t2 subdirectory:
# print("-----------t2 conftest-----------")
Here is the result of the command: pytest -s
:
t1/test_pt1.py -----------t2 conftest-----------
-----------t1 conftest-----------
.
t2/test_pt2.py -----------t2 conftest-----------
-----------t1 conftest-----------
.
pytest-bbd version: 4.1.0 pytest version: 6.2.4
Actually there is a closed issue related this problem.
Given structure:
tests_ ---- |- a_step_defs ----------|- test_using_first.py ----------|- conftest.py ---- |- b_step_defs ----------|- test_using_second.py ----------|- conftest.py
When I have
pytest_bdd_after_step()
in bothconftest.py
And I execute feature file that points toa_step_defs/test_using_first.py
Then only
pytest_bdd_after_step()
from theb_step_defs/conftest.py
is executed.Seems like having
conftest.py
in separate directory, does not separatepytest_bdd_after_step()
Pytest documentation says conftest.py: local per-directory plugins local conftest.py plugins contain directory-specific hook implementations. Session and test running activities will invoke all hooks defined in conftest.py files closer to the root of the filesystem.