pytest-dev / pytest-bdd

BDD library for the py.test runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.27k stars 214 forks source link

Parallel running feature file sharing the same step python file ? #648

Closed chunji08 closed 5 months ago

chunji08 commented 8 months ago

BACKGROUND:

I am exploring the possibility to use this framework for my scalability checking on my project.

DETAILS:

let's say I have these 2 feature file, which are checking different key-word on the DuckDuckGo page.

panda.feature

  Background:
    Given the DuckDuckGo home page is displayed

  Scenario: Basic DuckDuckGo Search panda
    When the user searches for "panda"
    Then results are shown for "panda"

goose.feature

  Background:
    Given the DuckDuckGo home page is displayed

  Scenario: Basic DuckDuckGo Search goose
    When the user searches for "goose"
    Then results are shown for "goose"

And I want to have both cases executed in parallel way.

These are the extra steps:

  1. have pytest-xdlist package installed.
  2. Create 2 separated step python file, which are mapped to individual feature file,
    • 1st step python file, test_web_panda.py, which is for"scenarios('../features/panda.feature')"
    • 2nd step python file, test_web_googse.py, which is for "scenarios('../features/goose.feature')"

So I did, and both test feature are executed in parallel.

But what I have realized is, although there is only the searching key-word difference in both cases, they could not share the same python step file, if I want both cases running in parallel ?

comments ?

Thanks,

Jack

MartinB134 commented 7 months ago

Does it work fine without parallel execution? And how to you share the steps? I can not seem to make it work to have an individual step in each py file and still share it with another feature file in a scenario decorator. Would also be interesting, if you share the steps via conftest or imported module, whatever is the other option of what you have implemented.

AmirYa412 commented 5 months ago

From what I understand this should not work without parallel either.

Sharing steps in pytest-bdd can be tricky, you need to import the step functions in your test_x.py for them to be available in x.future. The issue for me was when I imported steps from a file that has scenario("...feature") in it, resulted in tests running twice.

My solution was to defined feature steps in another file next to test_x.py and import all steps.py files in conftest.py - which made all steps available on any feature file across my project, beside those in test_x.py (which I use for assertions on x.feature only). I have made a small project in my github showing this.

youtux commented 5 months ago

please provide an MVCE to reproduce the issue, otherwise I won't be able to help.

Closing this until you can provide more info.