In the above example, the object returned from the device can be set as an attribute of the test class. Any methods of this class will have access.
import pytest
class TestAAA():
@pytest.fixture(scope="class", autouse=True)
def setup(self, myfixture):
TestAAA.myfixture = myfixture
def test_function1(self):
assert self.myfixture == "myfixture"
or if you inherit from unittest.Testcaseyou can do the following
import pytest
from unittest import TestCase
class TestAAA(TestCase):
@pytest.fixture(scope="class", autouse=True)
def setup(self, myfixture):
self.myfixture = myfixture
def test_function1(self):
self.assertEqual(self.myfixture, "myfixture")
source
share