Home > Back-end >  Getting fixture 'setup' not found error while running pytest
Getting fixture 'setup' not found error while running pytest

Time:07-28

I am getting following error while running pytest using following code im unable to figure out whats wrong please find below code snippets.

Console ouput :

PS C:\Bhargav\Python Learning\Projects\MBDailyBoost> pytest
================================================================================= test session starts =================================================================================
platform win32 -- Python 3.10.2, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Bhargav\Python Learning\Projects\MBDailyBoost
plugins: allure-pytest-2.9.45, html-3.1.1, metadata-2.0.2
collected 2 items
E       fixture 'setup' not found
>       available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, extra, include_metadata_in_junit_xml, metadata, monkeypatch, pytestconfig, recor
d_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
>       use 'pytest --fixtures [testpath]' for help on them.

C:\Bhargav\Python Learning\Projects\MBDailyBoost\testCases\test_login.py:22
=============================================================================== short test summary info =============================================================================== 
ERROR testCases/test_login.py::Test_001_Login::test_homePageTitle
ERROR testCases/test_login.py::Test_001_Login::test_Login

My conftest.py file contains below code:

import pytest
from selenium import webdriver

@pytest.fixture(scope="class")
def setup():
    global driver
    # driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
    driver = webdriver.Chrome()
    driver.maximize_window()

    return driver

My test_login.py file contains below code:

import time
from pageObjects.LoginPageGMB import LoginPage

class Test_001_Login:
    baseURL = ""
    usename = ""
    password = ""

    def test_homePageTitle(self, setup):
        self.driver = setup
        self.driver.get(self.baseURL)
        self.driver.maximize_window()
        actual_title = self.driver.title
        if actual_title == "Google Business Profile – Get Listed on Google":
            assert True
        else:
            assert False

CodePudding user response:

  1. Keep both code snippets in the same module
  2. declare all your fixtures inside conftest.py under test folder.
  • Related