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

How to apply for function/module/package/session scope to feature #687

Closed gy95 closed 7 months ago

gy95 commented 7 months ago

I know pytest-bdd can use pytest scope(function/module/package/session) by define a fixture by using scope="module", but this scope is belong to step file? i'm not really sure about this But how to apply scope(like package) to a feature file

For example, i have a feature definition like below

Feature: feature one

  Background:
    # My requirement is that execute this step once when I run two scenarios: a and b.
    # how to apply this?
    Given step executed only once for both a and b

  Scenario: scenario a
    When sleep one second

  Scenario: scenario b
    When sleep one second

My requirement is that the Given step step executed only once for both a and b will only be executed only once when I run the two scenarios a and b. Can this requirement be met?

gy95 commented 7 months ago

@youtux can this issue be fixed? Thanks a lot :)

youtux commented 7 months ago

Steps functions are not fixtures.

You can instead make a function decorator that prevents the function to execute a second time.