Request for Supporting Dynamic Import in pytest_bdd_before_scenario
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu với hook pytest_bdd_before_scenario được mô tả trong hooks.py và so sánh nó với conftest.py ví dụ cùng các module step trong tests/steps/. Tái hiện bố cục scenario của feature_a và feature_b, sau đó tìm hiểu cách các định nghĩa được import động được đăng ký. Được xem là hoàn tất khi các import được chọn theo đường dẫn feature hoặc các tag được nhận diện trong quá trình thực thi mà không yêu cầu tất cả module step phải được import trên toàn cục.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I would like to request support for dynamically importing step definitions in the pytest_bdd_before_scenario hook. This feature would greatly enhance the flexibility and modularity of test setups, especially in large projects with multiple feature files and step definitions.
Current Behavior: Currently, pytest-bdd does not provide a straightforward way to dynamically import step definitions based on the feature file being executed. While it is possible to use importlib to import modules dynamically, the step definitions are not registered correctly, leading to issues where steps are not found during test execution.
Proposed Enhancement: Enhance the pytest_bdd_before_scenario hook to support dynamic import and registration of step definitions. This could involve:
- Allowing dynamic import of step definition modules based on the feature file path or tags.
- Ensuring that dynamically imported step definitions are correctly registered and recognized by pytest-bdd.
Use Case: In large projects with multiple feature files and step definitions, it is often necessary to organize step definitions into separate modules. Dynamically importing and registering these step definitions based on the feature file being executed would:
- Improve modularity and maintainability of the test code.
- Reduce the need for importing all step definitions globally, which can lead to namespace conflicts and increased memory usage.
- Allow for more flexible and scalable test setups.
Example Scenario: Consider a project with the following structure:
project_root/
tests/
features/
feature_a/
feature_a.feature
feature_b/
feature_b.feature
steps/
test_feature_a.py
test_feature_b.py
conftest.py
hooks.py
In the hooks.py file, we would like to dynamically import and register the appropriate step definitions based on the feature file being executed:
import importlib
from pytest_bdd import before_scenario
def pytest_bdd_before_scenario(request, feature, scenario):
feature_path = feature.filename
if 'feature_a' in feature_path:
importlib.import_module('tests.steps.test_feature_a')
elif 'feature_b' in feature_path:
importlib.import_module('tests.steps.test_feature_b')
With the proposed enhancement, pytest-bdd would ensure that the dynamically imported step definitions are correctly registered and recognized during test execution.
Thank you for considering this enhancement request. I look forward to your feedback and hope to see this feature implemented in a future release.
- Ngôn ngữ chính
- Python
- Star
- 1.5k
- Fork
- 251
- Merge trung bình
- 43 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytest-dev/pytest-bdd
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
pytest-dev/pytest-bdd#805 ·
-
YAML support removed in v8Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
pytest-dev/pytest-bdd#785 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
pytest-dev/pytest-bdd#784 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
pytest-dev/pytest-bdd#782 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
pytest-dev/pytest-bdd#780 · 3 reaction ·
Tất cả issue của pytest-dev/pytest-bdd
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
spec-kitty/spec-kitty#5319 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend::vllm diffusion multimodal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
openai/openai-agents-python#5229 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày