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
Parametrization with Variables Unexpectedly Changes Fixture Scope from Class-Level to Function-Level #12146
Comments
Slightly simpler example: import pytest
@pytest.mark.usefixtures("fixt")
class TestSmoke:
def test_1(self):
assert True
def test_2(self):
assert True import pytest
def pytest_generate_tests(metafunc):
if "fixt" in metafunc.fixturenames:
arg = "latest"
metafunc.parametrize(
"fixt",
argvalues=[
(
arg,
# "latest",
)
],
indirect=True,
scope="class",
)
@pytest.fixture
def fixt(request):
yield with tests/test_app.py
SETUP F fixt[('latest',)]
tests/test_app.py::TestSmoke::test_1[fixt0] (fixtures used: fixt, request).
TEARDOWN F fixt[('latest',)]
SETUP F fixt[('latest',)]
tests/test_app.py::TestSmoke::test_2[fixt0] (fixtures used: fixt, request).
TEARDOWN F fixt[('latest',)] but when commenting out tests/test_app.py
SETUP F fixt[('latest',)]
tests/test_app.py::TestSmoke::test_1[fixt0] (fixtures used: fixt, request).
tests/test_app.py::TestSmoke::test_2[fixt0] (fixtures used: fixt, request).
TEARDOWN F fixt[('latest',)] I'm... completely flabbergasted. How is this even possible‽ |
@The-Compiler i suspect/fear we somewhere match object identities when the string is passed as a constant, its likely the python interpreter render it as single tuple value instead of creating it if that suspicion holds true, then can expect the behaviour as you observe |
i jsut made a small test in ipython on python 3.12
|
its possible #11257 fixes this |
I have a
setup
fixture that I've parameterized with class-level scope. When I directly specify the argument values as[("chrome", "windows", "latest")]
, it works fine, maintaining the class-level scope. However, when I try to use variables to set these argument values, I've noticed that the scope unexpectedly shifts to function-level.tests/test_app.py
Scenario 1 with hardcoded values
tests/conftest.py
Output
Scenario 2 with variable values
tests/conftest.py
Output
The text was updated successfully, but these errors were encountered: