Code Monkey home page Code Monkey logo

Comments (6)

dcendents avatar dcendents commented on August 24, 2024 1

I created the PR

from pytest-bdd.

slafs avatar slafs commented on August 24, 2024 1

We have this problem too (pytest==8.2.2 and pytest-bdd==7.2.0).
The PR by @dcendents fixes it 👍.

from pytest-bdd.

martinwilkerson-ons avatar martinwilkerson-ons commented on August 24, 2024

We are seeing this too, combinations tested that failed to behave as expected:

  • pytest 8.1.2, pytest-bdd 7.1.2
  • pytest 8.2.0, pytest-bdd 7.1.2

Downgrading to pytest 7.4.4 fixes it.

from pytest-bdd.

dcendents avatar dcendents commented on August 24, 2024

I don't have time to open a pull request right now, will try to eventually but this seems to work (I modified the file locally in my venv and executed my BDD tests and they all pass with pytest-bdd 7.1.2 and pytest 8.2.0).

Changes between releases 7.0.1 and 7.1.2: 7.0.1...7.1.2

file src/pytest_bdd/compat.py has been added with two methods to register a fixture, one for pytest 8.1+ and one for older pytest version.

I simply copied the inject_fixture function from pytest < 8.1 and adapted the arguments to create the FixtureDef with the correct arguments since pytest 8.1 and left the rest as is and it seems to work:

    def inject_fixture(request: FixtureRequest, arg: str, value: Any) -> None:
        """Inject fixture into pytest fixture request.

        :param request: pytest fixture request
        :param arg: argument name
        :param value: argument value
        """
        fd = FixtureDef(
            config=request._fixturemanager.config,
            baseid=request.node.nodeid,
            argname=arg,
            func=lambda: value,
            scope="function",
            params=None,
            ids=None,
            _ispytest=True,
        )

        fd.cached_result = (value, 0, None)

        old_fd = request._fixture_defs.get(arg)
        add_fixturename = arg not in request.fixturenames

        def fin() -> None:
            request._fixturemanager._arg2fixturedefs[arg].remove(fd)

            if old_fd is not None:
                request._fixture_defs[arg] = old_fd

            if add_fixturename:
                request._pyfuncitem._fixtureinfo.names_closure.remove(arg)

        request.addfinalizer(fin)

        # inject fixture definition
        request._fixturemanager._arg2fixturedefs.setdefault(arg, []).append(fd)

        # inject fixture value in request cache
        request._fixture_defs[arg] = fd
        if add_fixturename:
            request._pyfuncitem._fixtureinfo.names_closure.append(arg)

If someone wants to open a PR and make sure it doesn't break anything please feel free to do so. Otherwise I'll get to it eventually...

Cheers,

from pytest-bdd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.