pytest testing framework in the above codeeach of the test functions accepts the calculator fixture that is used to instantiate the calculator object we have therefore de-duplicated our codethere is now only one piece of code that defines how calculator object should be created for our tests note each test is supplied with completely new instance of the calculator objectthere is therefore no chance of one test impacting on another test it is also considered good practice to add docstring to your fixtures as we have done above this is because pytest can produce list of all fixtures available along with their docstrings from the command line this is done usingpytest fixtures the pytest fixtures can be applied to functions (as above)classesmodulespackages or sessions the scope of fixture can be indicated via the (optionalscope parameter to the fixture decorator the default is "functionwhich is why we did not need to specify anything above the scope determines at what point fixture should be run for examplea fixture with 'sessionscope will be run once for the test sessiona fixture with module scope will be run once for the module (that is the fixture and anything it generates will be shared across all tests in the current module) fixture with class scope indicates fixture that is run for each new instance of test class created etc another parameter to the fixture decorator is autouse which if set to true will activate the fixture for all tests that can see it if it is set to false (which is the defaultthen an explicit reference in test function (or method etc is required to activate the fixture if we add some additional fixtures to our tests we can see when they are runimport pytest from calculator import calculator @pytest fixture(scope='session'autouse=truedef session_scope_fixture()print('session_scope_fixture'@pytest fixture(scope='module'autouse=truedef module_scope_fixture()print('module_scope_fixture'@pytest fixture(scope='class'autouse=truedef class_scope_fixture()print('class_scope_fixture'@pytest fixture def calculator()"""returns calculator instance""print('calculator fixture'return calculator(