pytest-dev / pytest-bdd

BDD library for the pytest runner

Home Page:https://pytest-bdd.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import from steps with a target_fixture collects the same test twice?

AmirYa412 opened this issue · comments

I am working on a refactoring a project from Behave to pytest-bdd.
Structure looks like this:

|---features
|          |---publish.feature
|---steps_def
|          |---conftest.py
|          |---test_article.py
|          |---test_publish.py     # scnearios() defined here


We have an internal Driver we initialise in conftest.py
In test_article.py I have steps that can be related to all features, "common steps".
I want to use defined steps freely in feature files, and use their target_fixture between other steps files.

I noticed few issues that stopping us from fully moving to pytest-bdd:

  • Importing in test_publish.py steps or target_fixtures from test_article.py will collect the same scenario twice, in report I see the same scnario running from test_aritcle.py and test_publish.py.
  • To use shared fixtures or steps I can define them in conftest.py, but is it really optimal? It will eventually create a really big conftest.py files, which I believe should contain configurations and not test related functions.
  • If I don't import from test_publish.py and define the target_fixtures in conftest.py, I am getting: pytest_bdd.exceptions.StepDefinitionNotFoundError when running masks.feature.
  • Only solution I can think of is creating a fixture in conftest.py - a fixture called context and pass it throughout the tests - but that's the reason we are moving from Behave - we don't want to use context.

I encountered the same issue. I will keep an eye on it.
next is the structure of my projects:

`

features:
| -- test.feature
| -- conftest.py: import all the functions from 3 test_steps py files
| -- steps_def

| -- test_step1.py
| -- test_step2.py
| -- test_step3.py`

my problem is:
when the project has 3 test_step.py files, the report is: 3 passed, 18 deselected, 2 warnings
but if I remove test_step3.py, and run the case again, the report is: 2 passed, 12 deselected, 2 warnings

I found you have already closed the issue.
so could you tell me how to resolve this issue? thanks a lot!!