Python [求助] 在 Linux 下执行 web 自动化测试,pytest 报错了,大家帮忙看看这是啥问题啊?

jiawei.li · 2020年12月21日 · 最后由 陈恒捷 回复于 2020年12月22日 · 194 次阅读
[root@XXXX]# python run.py 
=========================================== test session starts ===========================================
platform linux -- Python 3.7.4, pytest-5.2.2, py-1.10.0, pluggy-0.13.1
rootdir: /data/XXXX, inifile: pytest.ini
plugins: allure-pytest-2.8.16, html-2.1.1, metadata-1.11.0
collecting ... http://XXXX.net/
TGT
collected 21 items                                                                                        

TestCase/test_home.py 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/main.py", line 193, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/main.py", line 237, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/main.py", line 258, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/runner.py", line 80, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/runner.py", line 89, in runtestprotocol
INTERNALERROR>     rep = call_and_report(item, "setup", log)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/_pytest/runner.py", line 178, in call_and_report
INTERNALERROR>     report = hook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 93, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/manager.py", line 87, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/usr/local/python3/lib/python3.7/site-packages/pluggy/callers.py", line 203, in _multicall
INTERNALERROR>     gen.send(outcome)
INTERNALERROR>   File "/data/XXXX/conftest.py", line 73, in pytest_runtest_makereport
INTERNALERROR>     screen_img = _capture_screenshot()
INTERNALERROR>   File "/data/XXXX/conftest.py", line 149, in _capture_screenshot
INTERNALERROR>     driver.save_screenshot(screen_path)
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'save_screenshot'

========================================== no tests ran in 0.25s =========================================

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 4 条回复 时间 点赞

没源码?

Jerry li 回复

帮忙看下😀

jiawei.li 回复

看起来是你 driver 没有初始化成功吧,看一下你具体的代码吧,这些都是报错信息

INTERNALERROR>   File "/data/longfor_oa/conftest.py", line 149, in _capture_screenshot
INTERNALERROR>     driver.save_screenshot(screen_path)
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'save_screenshot'

/data/longfor_oa/conftest.py 这个文件的内容发上来吧,从日志上看,直接原因是调用 save_screenshot 时,driver 对象还是没被初始化,还是最初的 None 。但具体为啥是 None ,不看你写的代码看不出来的。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册