Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with existing working automation after python 3.11.1 and pytest-bdd 7.00 upgrade #685

Closed
Enigmaderockz opened this issue Mar 28, 2024 · 6 comments

Comments

@Enigmaderockz
Copy link

I was using python 3.10.10 version and pytest-bdd version 4.1.0, below test case execution was working absolutely fine but when I upgraded from python 3.10.10 to 3.11.1 and pytest-bdd version to 7.0.0 then I am getting below error

error:

pytest_bdd/scenario.py, line 217
@pytest.mark.usefixtures*func_args)
def scenario wrapper/request: FixtureRequest, _pytest_bdd_example: dict(str, str]) → Any:
E                   fixture 'conf' not found

This is feature file sample abc.feature

Feature: load

Background:
        Given config file <conf> for product "XYZ" and TestCaseld <id>

@tc
Scenario Outline: tc1
        Then data between source file and table should match
        Examples:
        | conf | id |
        |abc.cfg |load1 |

This is test case file sample: test_abc.py

from pytest bad import scenarios, given, when, then, parsers
import pytest
import os

scenarios("./feature/")

def check():
    print("passed")

@pytest.fixture
def  job_details(conf, id):
    return dict(conf=conf, id=id)

@given(parsers.parse('config file <conf> for product "(product)" and TestCaseld <id>'))
def job_details(conf, product, id):
    print(conf + product + id)


@youtux
Copy link
Contributor

youtux commented Mar 28, 2024

You have to use the target_fixture=“conf” parameter. Che the migration guide to pytest-bed v7 in the readme of the project.

@youtux youtux closed this as completed Mar 28, 2024
@Enigmaderockz
Copy link
Author

Enigmaderockz commented Mar 28, 2024

yes I have used that but again stuck with parametrization of conf and id values from all the test cases. I am able to hardcode one specific conf and id value in conf and id fixtures.

Feature: load

Background:
        Given config file <conf> for product "ETMARGIN" and TestCaseld <id>

@tc
Scenario Outline: tc1
        Then data between source file and table should match
        Examples:
        | conf | id |
        |abc.cfg |load1 |
        |def.cfg |load3 |

@tc
Scenario Outline: tc1
        Then data between source file and table should match
        Examples:
        | conf | id |
        |xyz.cfg |load2 |

This is test case file sample: test_abc.py

from pytest bad import scenarios, given, when, then, parsers
import pytest
import os

scenarios("./feature/")

def check():
    print("passed")

@pytest.fixture
def  conf():
    return 'abc.cfg'

@pytest.fixture
def  id():
    return 'load1'

@given(parsers.parse('config file <conf> for product "(product)" and TestCaseld <id>'))
def job_details(conf, product, id):
    print(conf + product + id)

@Enigmaderockz
Copy link
Author

I think I can not do it or is there any other way because this is what I got to know from documentation:

(https://pytest-bdd.readthedocs.io/en/stable/#refuse-combining-scenario-outline-and-pytest-parametrization)
The significant downside of combining scenario outline and pytest parametrization approach was an inability to see the test table from the feature file.

@youtux
Copy link
Contributor

youtux commented Mar 29, 2024

Sorry, I don’t understand what you’re trying to do here

@Enigmaderockz
Copy link
Author

Enigmaderockz commented Mar 31, 2024

@youtux - Sorry for late reply. What I am trying to do here is I am trying to pass the parameter values from scenario outline examples to the given statement in test case in test_abc.py.

What I showed you in above comment is I am able to pass abc.cfg and load1 to the given statement by hardcoding it in test_abc.py using conf and id fixtures but how should I pass other scenario outline examples like def.cfg & load3, xyz.cfg and load2 in feature file to the given statement in test_abc.py?

Isn't there any way to parameterize these scenario outline examples in test_abc.py so that and in given, when and then statemen test cases in test_abc.py should pick up these outline examples values from conf and id from feature file when it comes to execution?

I am able to achieve using pytest-bdd 4.1.0 and python 3.10.10 but unable to do so in upgraded versions.

If you can help, then that would be really great. I couldn't find any solution of this anywhere not even using AI tools.

@youtux
Copy link
Contributor

youtux commented Mar 31, 2024

Have you tried:

@dataclass
class JobDetails:
    conf: str
    product: str
    id: str
@given(parsers.parse('config file <conf> for product "(product)" and TestCaseld <id>'), target_fixture=job_details”)
def _(conf, product, id):
    return JobDetails(conf, product, id)

then in your given/when/then steps you can use the job_details fixture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants