pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.32k stars 221 forks source link

To get the current executing feature file name #613

Closed CuriousQA closed 1 year ago

CuriousQA commented 1 year ago

how to get the current feature file which is under execution.

My project structure:

- features/
  - feature1.feature
  - feature2.feature
- tests/
  - test_check.py

test_check.py has

from pytest_bdd import scenario, scenarios, given, when, then, parsers

scenarios('../feature')

Able to get the function for the scenario request.node.nodeid gives scenario outline examples. However, is there a way to get the feature file name during the execution of test in any of the @Given or @when methods.

mszpulak commented 1 year ago

same here

youtux commented 1 year ago

you should be able to request the request fixture in your step definitions:


@given("There is a foo")
def _(request):
    print(request.node.nodeid)
    return 42