Reputation: 115
I am in the process of creating an automation framework using selenium and python so in my conftest.py file I have used fixtures but when I am running my test cases through cmd line I am getting error
I have checked again and again but I am not getting the root cause for this error
This code is under my conftest.py file
import pytest
@pytest.fixture(scope="class")
def test_setup(request):
from selenium import webdriver
browser = request.config.getoption("--browser")
if browser == "chrome":
driver = webdriver.Chrome(executable_path="/home/akash/PycharmProjects/AutomationFramework/drivers/chromedriver")
request.cls.driver = driver
yield
driver.quit()
And below is the test case file
@pytest.mark.usefixtures("test_setup")
class TestLogin:
def test_login(self):
driver = self.driver
driver.get(utils.URL)
When I am running the command as python -m pytest I am getting the below error However, it should have opened up the browser and do the job
Error which I am getting
rootdir: /home/akash/PycharmProjects/AutomationFramework
plugins: html-1.21.1, metadata-1.8.0
collected 2 items
tests/login_test.py EE [100%]
======================================================================= ERRORS =======================================================================
_______________________________________________________ ERROR at setup of TestLogin.test_login _______________________________________________________
cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7f8e17b4ed08>, when = 'setup'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)
@classmethod
def from_call(cls, func, when, reraise=None):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
start = time()
excinfo = None
try:
> result = func()
venv/lib/python3.6/site-packages/_pytest/runner.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.6/site-packages/_pytest/runner.py:192: in <lambda>
lambda: ihook(item=item, **kwds), when=when, reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/runner.py:110: in pytest_runtest_setup
item.session._setupstate.prepare(item)
venv/lib/python3.6/site-packages/_pytest/runner.py:359: in prepare
col.setup()
venv/lib/python3.6/site-packages/_pytest/python.py:1455: in setup
fixtures.fillfixtures(self)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:288: in fillfixtures
request._fillfixtures()
venv/lib/python3.6/site-packages/_pytest/fixtures.py:461: in _fillfixtures
item.funcargs[argname] = self.getfixturevalue(argname)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:471: in getfixturevalue
return self._get_active_fixturedef(argname).cached_result[0]
venv/lib/python3.6/site-packages/_pytest/fixtures.py:494: in _get_active_fixturedef
self._compute_fixture_value(fixturedef)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:575: in _compute_fixture_value
fixturedef.execute(request=subrequest)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:883: in execute
return hook.pytest_fixture_setup(fixturedef=self, request=request)
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/fixtures.py:923: in pytest_fixture_setup
result = call_fixture_func(fixturefunc, request, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fixturefunc = <function test_setup at 0x7f8e17b61f28>, request = <SubRequest 'test_setup' for <Function test_login>>
kwargs = {'request': <SubRequest 'test_setup' for <Function test_login>>}
def call_fixture_func(fixturefunc, request, kwargs):
yieldctx = is_generator(fixturefunc)
if yieldctx:
it = fixturefunc(**kwargs)
> res = next(it)
E StopIteration
venv/lib/python3.6/site-packages/_pytest/fixtures.py:779: StopIteration
______________________________________________________ ERROR at setup of TestLogin.test_logout _______________________________________________________
cls = <class '_pytest.runner.CallInfo'>, func = <function call_runtest_hook.<locals>.<lambda> at 0x7f8e179ba048>, when = 'setup'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)
@classmethod
def from_call(cls, func, when, reraise=None):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
start = time()
excinfo = None
try:
> result = func()
venv/lib/python3.6/site-packages/_pytest/runner.py:220:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.6/site-packages/_pytest/runner.py:192: in <lambda>
lambda: ihook(item=item, **kwds), when=when, reraise=reraise
venv/lib/python3.6/site-packages/pluggy/hooks.py:289: in __call__
return self._hookexec(self, self.get_hookimpls(), kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:87: in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
venv/lib/python3.6/site-packages/pluggy/manager.py:81: in <lambda>
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
venv/lib/python3.6/site-packages/_pytest/runner.py:110: in pytest_runtest_setup
item.session._setupstate.prepare(item)
venv/lib/python3.6/site-packages/_pytest/runner.py:359: in prepare
col.setup()
venv/lib/python3.6/site-packages/_pytest/python.py:1455: in setup
fixtures.fillfixtures(self)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:288: in fillfixtures
request._fillfixtures()
venv/lib/python3.6/site-packages/_pytest/fixtures.py:461: in _fillfixtures
item.funcargs[argname] = self.getfixturevalue(argname)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:471: in getfixturevalue
return self._get_active_fixturedef(argname).cached_result[0]
venv/lib/python3.6/site-packages/_pytest/fixtures.py:494: in _get_active_fixturedef
self._compute_fixture_value(fixturedef)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:575: in _compute_fixture_value
fixturedef.execute(request=subrequest)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:874: in execute
raise val.with_traceback(tb)
venv/lib/python3.6/site-packages/_pytest/fixtures.py:923: in pytest_fixture_setup
result = call_fixture_func(fixturefunc, request, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
fixturefunc = <function test_setup at 0x7f8e17b61f28>, request = <SubRequest 'test_setup' for <Function test_login>>
kwargs = {'request': <SubRequest 'test_setup' for <Function test_login>>}
def call_fixture_func(fixturefunc, request, kwargs):
yieldctx = is_generator(fixturefunc)
if yieldctx:
it = fixturefunc(**kwargs)
> res = next(it)
E StopIteration
venv/lib/python3.6/site-packages/_pytest/fixtures.py:779: StopIteration
Upvotes: 0
Views: 1830
Reputation: 115
I got the solution it was because of indention only so when I write
import pytest
@pytest.fixture(scope="class")
def test_setup(request):
from selenium import webdriver
browser = request.config.getoption("--browser")
if browser == "chrome":
driver = webdriver.Chrome(executable_path="/home/akash/PycharmProjects/AutomationFramework/drivers/chromedriver")
request.cls.driver = driver
yield
driver.quit()
so in the above statement after line where I am setting up the executable path the next line is for the function which I have created so those statements come under that function and not on if statement that's why it was giving the above saidd error.
Upvotes: 2