-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Description
[Edit: Bug repro is further simplified. Please see the repro code below]
Hi, I found a case when class scope fixture is recognized as function scope, which fails the test with error "You tried to access the 'function' scoped fixture '...' with a 'class' scoped request object"
Could you please confirm if this is a pytest bug, or if this is not an encouraged pattern and I should try to implement it differently?
platform win32 -- Python 3.6.6, pytest-3.7.3, py-1.5.4, pluggy-0.7.1
@pytest.fixture(scope="class")
def class_dep(request):
print("Fixture setup")
@pytest.fixture(scope="function")
def func_dep():
pass
@pytest.mark.usefixtures("class_dep")
@pytest.mark.parametrize('class_dep', [10,20], indirect=True)
class TestScenario():
def test_foo(self, func_dep):
pass
def test_bar(self):
pass
> pytest.exe "test_foo1.py::TestScenario" -v -s
test_foo1.py::TestScenario::test_foo[10] Fixture setup
PASSED
test_foo1.py::TestScenario::test_foo[20] Fixture setup
PASSED
test_foo1.py::TestScenario::test_bar[10] Fixture setup
PASSED
test_foo1.py::TestScenario::test_bar[20] Fixture setup
PASSED
"Fixture setup" is printed 4 times.
If I change def test_foo(self, func_dep): to drop reference to func_dep, then it works as expected ("Fixture setup is printed 2 times").
Metadata
Metadata
Assignees
Labels
No labels