-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectly
Description
Hi all,
I'm using inheritance in my tests and base class have fixture(scope="class", autouse=True).
As a result I expecting that this fixture will be executed for each child class.
import pytest
class BaseTestClass:
test_func_scope_set = None
test_class_scope_set = None
@pytest.fixture(scope='class', autouse=True)
def dummy_class_fixture(self):
self.test_class_scope_set = True
@pytest.fixture(scope='function', autouse=True)
def dummy_func_fixture(self):
self.test_func_scope_set = True
class TestDummy(BaseTestClass):
def test_dummy(self):
assert self.test_func_scope_set is True
assert self.test_class_scope_set is TrueBut it was not executed(value of self.test_class_scope_set is None, but expecting True):
$ pytest main.py --disable-warnings
==================================================================================== test session starts =====================================================================================
platform linux -- Python 3.8.4, pytest-6.2.1, py-1.11.0, pluggy-0.13.1
rootdir: /home/shamray/src/tmp
plugins: forked-1.4.0, dynamicrerun-1.1.1, metadata-2.0.2, json-report-1.2.1, repeat-0.9.1, xdist-2.5.0, pytest_check-0.3.9
collected 1 item
main.py F [100%]
========================================================================================== FAILURES ==========================================================================================
____________________________________________________________________________________ TestDummy.test_dummy ____________________________________________________________________________________
self = <main.TestDummy object at 0x7f45392b9100>
def test_dummy(self):
assert self.test_func_scope_set is True
> assert self.test_class_scope_set is True
E assert None is True
E + where None = <main.TestDummy object at 0x7f45392b9100>.test_class_scope_set
main.py:21: AssertionError
================================================================================== Dynamically rerun tests ===================================================================================
================================================================================== short test summary info ===================================================================================
FAILED main.py::TestDummy::test_dummy - assert None is True
================================================================================ 1 failed, 1 warning in 0.07s ================================================================================Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectly