we are creating tests by implementing unittest and pytest in python. we want to use fixtures for doing setup and tear down at session and test level. How to use object created in setup session fixture to be used in setup of function fixture. Example I want to create a driver object like driver = webdriver.Chrome() of intializing the browser and using the driver object in test methods and function scope fixture.
conftest.py import pytest
@pytest.fixture(scope="session")
def setupsession():
print("Starting Session")
yield
print("Ending Session")
@pytest.fixture(scope="module")
def setupmodule(request):
print("starting module")
yield
print("Ending Module")
@pytest.fixture(scope="class")
def setupclass(request):
print("starting module")
yield
print("Ending Module")
Basetest.py import unittest
class BaseTest(unittest.TestCase):
def setUp(self):
print("inside Base setup")
def tearDown(self):
print("inside base teardown")
test.py import pytest from wav2.fixtures.base_test import BaseTest
@pytest.mark.usefixtures("setupsession", "setupmodule")
class TestSample(BaseTest):
def test1(self):
print("calling inside test test1")
self.assertTrue(False)
def test2(self):
print("calling inside test tes`enter code here`t2")