Здравствуй, коллективный разум. Проблема заключается в следующем
Изучал pytest и попытался сделать парочку тестов на связке selene + pytest.
У меня получилось
Но вот беда: когда я пытаюсь запускать эти же тесты из PyCharm, выполнение падает с вот каким сообщением:
Код
/home/ilya/PycharmProjects/learning_pytest/venv/bin/python /home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/_jb_pytest_runner.py --target test_stam.py::test_sum
Launching pytest with arguments test_stam.py::test_sum in /home/ilya/PycharmProjects/learning_pytest/test
============================= test session starts ==============================
platform linux -- Python 3.6.6, pytest-3.10.0, py-1.7.0, pluggy-0.8.0
rootdir: /home/ilya/PycharmProjects/learning_pytest/test, inifile:collected 1 item
test_stam.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/main.py", line 185, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/main.py", line 225, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/main.py", line 246, in pytest_runtestloop
INTERNALERROR> item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/runner.py", line 77, in pytest_runtest_protocol
INTERNALERROR> runtestprotocol(item, nextitem=nextitem)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/runner.py", line 86, in runtestprotocol
INTERNALERROR> rep = call_and_report(item, "setup", log)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/_pytest/runner.py", line 176, in call_and_report
INTERNALERROR> hook.pytest_runtest_logreport(report=report)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
INTERNALERROR> return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/home/ilya/PycharmProjects/learning_pytest/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "/home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/teamcity/pytest_plugin.py", line 313, in pytest_runtest_logreport
INTERNALERROR> self.teamcity.blockOpened(block_name, flowId=test_id)
INTERNALERROR> File "/home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/teamcity/messages.py", line 92, in blockOpened
INTERNALERROR> self.message('blockOpened', name=name, flowId=flowId)
INTERNALERROR> File "/home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/_jb_runner_tools.py", line 195, in message
INTERNALERROR> current, parent = TREE_MANAGER.node_ids
INTERNALERROR> File "/home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/_jb_runner_tools.py", line 148, in node_ids
INTERNALERROR> current = self._get_node_id(self.current_branch)
INTERNALERROR> File "/home/ilya/.local/share/JetBrains/Toolbox/apps/PyCharm-C/ch-0/182.4505.26/helpers/pycharm/_jb_runner_tools.py", line 140, in _get_node_id
INTERNALERROR> return self._node_ids_dict[".".join(branch)]
INTERNALERROR> KeyError: ''
PyCharm 2018.2, воспроизводится на Ubuntu и Маке.
Гуглил. Похожую проблему нашёл только на форуме software-testing:
http://software-testing.ru/forum/index.php?/topic/36059-python-selene-pytest-pycharm-internalerror-pri-zapuske-testov/
но там тоже ответа не нашли.
Из консоли запускать не вариант, потому, что дебажить неудобно.
Если не обращаться к селену, то падения не происходит.
А, ну да, код:
conftest.py:
@pytest.fixture(scope = "session")
def app(request):
browser.open_url("https://www.google.com")
return True
test_stam.py:
def test_sum(app):
assert 4 == 2 * 2
Upd:
Сам спросил - сам ответил. Драйвер надо инициализировать в фикстуре.
from selenium import webdriver
@pytest.fixture(scope = "session")
def app(request):
set_driver(webdriver.Chrome())